//########################################################################## //# # //# CLOUDCOMPARE # //# # //# This program is free software; you can redistribute it and/or modify # //# it under the terms of the GNU General Public License as published by # //# the Free Software Foundation; version 2 or later of the License. # //# # //# This program is distributed in the hope that it will be useful, # //# but WITHOUT ANY WARRANTY; without even the implied warranty of # //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # //# GNU General Public License for more details. # //# # //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) # //# # //########################################################################## #include "ccPrimitiveFactoryDlg.h" //local #include "mainwindow.h" #include "ccUtils.h" //qCC_db #include #include #include #include #include #include #include #include #include //system #include ccPrimitiveFactoryDlg::ccPrimitiveFactoryDlg(MainWindow* win) : QDialog(win) , Ui::PrimitiveFactoryDlg() , m_win(win) { assert(m_win); setupUi(this); connect(createPushButton, &QAbstractButton::clicked, this, &ccPrimitiveFactoryDlg::createPrimitive); connect(closePushButton, &QAbstractButton::clicked, this, &QDialog::accept); connect(spherePosFromClipboardButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setSpherePositionFromClipboard); connect(spherePosToOriginButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setSpherePositionToOrigin); connect(csSetMatrixBasedOnSelectedObjectButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setCoordinateSystemBasedOnSelectedObject); connect(csMatrixTextEdit, &QPlainTextEdit::textChanged, this, &ccPrimitiveFactoryDlg::onMatrixTextChange); connect(csClearMatrixButton, &QPushButton::clicked, this, &ccPrimitiveFactoryDlg::setCSMatrixToIdentity); setCSMatrixToIdentity(); } void ccPrimitiveFactoryDlg::createPrimitive() { if (!m_win) return; ccGenericPrimitive* primitive = nullptr; switch(tabWidget->currentIndex()) { //Plane case 0: { primitive = new ccPlane(static_cast(planeWidthDoubleSpinBox->value()), static_cast(planeHeightDoubleSpinBox->value())); } break; //Box case 1: { CCVector3 dims( static_cast(boxDxDoubleSpinBox->value()), static_cast(boxDyDoubleSpinBox->value()), static_cast(boxDzDoubleSpinBox->value())); primitive = new ccBox(dims); } break; //Sphere case 2: { ccGLMatrix transMat; transMat.setTranslation(CCVector3f(spherePosXDoubleSpinBox->value(), spherePosYDoubleSpinBox->value(), spherePosZDoubleSpinBox->value())); primitive = new ccSphere(static_cast(sphereRadiusDoubleSpinBox->value()), &transMat); } break; //Cylinder case 3: { primitive = new ccCylinder( static_cast(cylRadiusDoubleSpinBox->value()), static_cast(cylHeightDoubleSpinBox->value())); } break; //Cone case 4: { primitive = new ccCone( static_cast(coneBottomRadiusDoubleSpinBox->value()), static_cast(coneTopRadiusDoubleSpinBox->value()), static_cast(coneHeightDoubleSpinBox->value()), static_cast(snoutGroupBox->isChecked() ? coneXOffsetDoubleSpinBox->value() : 0), static_cast(snoutGroupBox->isChecked() ? coneYOffsetDoubleSpinBox->value() : 0)); } break; //Torus case 5: { primitive = new ccTorus(static_cast(torusInsideRadiusDoubleSpinBox->value()), static_cast(torusOutsideRadiusDoubleSpinBox->value()), static_cast( CCCoreLib::DegreesToRadians( torusAngleDoubleSpinBox->value() ) ), torusRectGroupBox->isChecked(), static_cast(torusRectGroupBox->isChecked() ? torusRectSectionHeightDoubleSpinBox->value() : 0)); } break; //Dish case 6: { primitive = new ccDish( static_cast(dishRadiusDoubleSpinBox->value()), static_cast(dishHeightDoubleSpinBox->value()), static_cast(dishEllipsoidGroupBox->isChecked() ? dishRadius2DoubleSpinBox->value() : 0)); } break; case 7: { bool valid = false; ccGLMatrix mat = getCSMatrix(valid); if (!valid) { mat.toIdentity(); } primitive = new ccCoordinateSystem(&mat); } break; } if (primitive) { primitive->setDrawingPrecision(precisionSpinBox->value()); m_win->addToDB(primitive, true, true, true); } } void ccPrimitiveFactoryDlg::setSpherePositionFromClipboard() { CCVector3d vector; if (ccUtils::GetVectorFromClipboard(vector)) { spherePosXDoubleSpinBox->setValue(vector.x); spherePosYDoubleSpinBox->setValue(vector.y); spherePosZDoubleSpinBox->setValue(vector.z); } } void ccPrimitiveFactoryDlg::setSpherePositionToOrigin() { spherePosXDoubleSpinBox->setValue(0); spherePosYDoubleSpinBox->setValue(0); spherePosZDoubleSpinBox->setValue(0); } void ccPrimitiveFactoryDlg::setCoordinateSystemBasedOnSelectedObject() { ccHObject::Container selectedEnt = m_win->getSelectedEntities(); for (auto entity : selectedEnt) { csMatrixTextEdit->setPlainText(entity->getGLTransformationHistory().toString()); } } void ccPrimitiveFactoryDlg::onMatrixTextChange() { bool valid = false; getCSMatrix(valid); if (valid) { ccLog::Print("Valid ccGLMatrix"); } } void ccPrimitiveFactoryDlg::setCSMatrixToIdentity() { csMatrixTextEdit->blockSignals(true); csMatrixTextEdit->setPlainText("1.00000000 0.00000000 0.00000000 0.00000000\n0.00000000 1.00000000 0.00000000 0.00000000\n0.00000000 0.00000000 1.00000000 0.00000000\n0.00000000 0.00000000 0.00000000 1.00000000"); csMatrixTextEdit->blockSignals(false); } ccGLMatrix ccPrimitiveFactoryDlg::getCSMatrix(bool& valid) { QString text = csMatrixTextEdit->toPlainText(); if (text.contains("[")) { //automatically remove anything between square brackets static const QRegExp squareBracketsFilter("\\[([^]]+)\\]"); text.replace(squareBracketsFilter, ""); csMatrixTextEdit->blockSignals(true); csMatrixTextEdit->setPlainText(text); csMatrixTextEdit->blockSignals(false); } ccGLMatrix mat = ccGLMatrix::FromString(text, valid); return mat; }