diff --git a/src/Mod/Part/Gui/ViewProviderReference.cpp b/src/Mod/Part/Gui/ViewProviderReference.cpp index 9b4913547..7f3c1eed4 100644 --- a/src/Mod/Part/Gui/ViewProviderReference.cpp +++ b/src/Mod/Part/Gui/ViewProviderReference.cpp @@ -54,8 +54,8 @@ # include # include # include -# include -# include +# include +# include # include # include # include @@ -98,7 +98,19 @@ PROPERTY_SOURCE(PartGui::ViewProviderPartReference, Gui::ViewProviderGeometryObj //************************************************************************** // Construction/Destruction -ViewProviderPartReference::ViewProviderPartReference() : pcControlPoints(0) +ViewProviderPartReference::ViewProviderPartReference() + : EdgeRoot(0) + , FaceRoot(0) + , VertexRoot(0) + , pcLineMaterial(0) + , pcPointMaterial(0) + , pcLineStyle(0) + , pcPointStyle(0) + , pcControlPoints(0) + , pShapeHints(0) + , meshDeviation(0.01f) + , noPerVertexNormals(true) + , qualityNormals(false) { App::Material mat; mat.ambientColor.set(0.2f,0.2f,0.2f); @@ -116,8 +128,8 @@ ViewProviderPartReference::ViewProviderPartReference() : pcControlPoints(0) //PointSize.setConstraints(&floatRange); //ADD_PROPERTY(PointSize,(2.0f)); //ADD_PROPERTY(ControlPoints,(false)); - //ADD_PROPERTY(Lighting,(1)); - //Lighting.setEnums(LightingEnums); + //ADD_PROPERTY(Lighting,(1)); + //Lighting.setEnums(LightingEnums); //EdgeRoot = new SoSeparator(); //EdgeRoot->ref(); @@ -142,11 +154,11 @@ ViewProviderPartReference::ViewProviderPartReference() : pcControlPoints(0) //pcPointStyle->ref(); //pcPointStyle->style = SoDrawStyle::POINTS; //pcPointStyle->pointSize = PointSize.getValue(); - - //pShapeHints = new SoShapeHints; - //pShapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; - //pShapeHints->ref(); - //Lighting.touch(); + + //pShapeHints = new SoShapeHints; + //pShapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE; + //pShapeHints->ref(); + //Lighting.touch(); sPixmap = "Tree_Part"; //loadParameter(); @@ -161,7 +173,7 @@ ViewProviderPartReference::~ViewProviderPartReference() //pcPointMaterial->unref(); //pcLineStyle->unref(); //pcPointStyle->unref(); - //pShapeHints->unref(); + //pShapeHints->unref(); } void ViewProviderPartReference::onChanged(const App::Property* prop) @@ -211,12 +223,12 @@ void ViewProviderPartReference::onChanged(const App::Property* prop) // App::Property* shape = obj->getPropertyByName("Shape"); // showControlPoints(ControlPoints.getValue(), shape); //} - //else if (prop == &Lighting) { - // if (Lighting.getValue() == 0) - // pShapeHints->vertexOrdering = SoShapeHints::UNKNOWN_ORDERING; - // else - // pShapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; - //} + //else if (prop == &Lighting) { + // if (Lighting.getValue() == 0) + // pShapeHints->vertexOrdering = SoShapeHints::UNKNOWN_ORDERING; + // else + // pShapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE; + //} //else { // ViewProviderGeometryObject::onChanged(prop); //} diff --git a/src/Mod/PartDesign/App/FeatureMultiTransform.cpp b/src/Mod/PartDesign/App/FeatureMultiTransform.cpp index 738368bfd..590df3706 100644 --- a/src/Mod/PartDesign/App/FeatureMultiTransform.cpp +++ b/src/Mod/PartDesign/App/FeatureMultiTransform.cpp @@ -124,6 +124,8 @@ const std::list MultiTransform::getTransformations(const std::vector(bodies[index]); diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index 6b689b835..2f433addf 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -208,6 +208,8 @@ std::vector TaskFeaturePick::buildFeatures() { int index = 0; std::vector result; auto activeBody = PartDesignGui::getBody(false); + if (!activeBody) + return result; auto activePart = PartDesignGui::getPartFor(activeBody, false); for (std::vector::const_iterator st = statuses.begin(); st != statuses.end(); st++) { diff --git a/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp b/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp index 9c9141c68..64e106c31 100644 --- a/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskMultiTransformParameters.cpp @@ -58,7 +58,7 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskMultiTransformParameters */ TaskMultiTransformParameters::TaskMultiTransformParameters(ViewProviderTransformed *TransformedView,QWidget *parent) - : TaskTransformedParameters(TransformedView, parent), subTask(NULL) + : TaskTransformedParameters(TransformedView, parent), subTask(nullptr), subFeature(nullptr) { // we need a separate container widget to add all controls to proxy = new QWidget(this); diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index 284b11f14..a8c8fcdbb 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -778,10 +778,11 @@ bool TaskDlgPipeParameters::accept() //we need to add the copied features to the body after the command action, as otherwise freecad crashs unexplainable for(auto obj : copies) { - if(pcActiveBody) - pcActiveBody->addFeature(obj); - else if (pcActivePart) - pcActivePart->addObject(obj); + //Dead code: pcActiveBody was previously used without checking for null, so it won't be null here either. + //if(pcActiveBody) + pcActiveBody->addFeature(obj); + //else if (pcActivePart) + // pcActivePart->addObject(obj); } } catch (const Base::Exception& e) { diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index 1edfe1b7a..236149446 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -94,30 +94,29 @@ const QString TaskSketchBasedParameters::onAddSelection(const Gui::SelectionChan void TaskSketchBasedParameters::onSelectReference(const bool pressed, const bool edge, const bool face, const bool planar) { // Note: Even if there is no solid, App::Plane and Part::Datum can still be selected - PartDesign::ProfileBased* pcSketchBased = static_cast(vp->getObject()); + PartDesign::ProfileBased* pcSketchBased = dynamic_cast(vp->getObject()); + if (pcSketchBased) { + // The solid this feature will be fused to + App::DocumentObject* prevSolid = pcSketchBased->getBaseObject( /* silent =*/ true ); - // The solid this feature will be fused to - App::DocumentObject* prevSolid = pcSketchBased->getBaseObject( /* silent =*/ true ); - - if (pressed) { - Gui::Document* doc = Gui::Application::Instance->activeDocument(); - if (doc) { - if (pcSketchBased) + if (pressed) { + Gui::Document* doc = vp->getDocument(); + if (doc) { doc->setHide(pcSketchBased->getNameInDocument()); - if (prevSolid) - doc->setShow(prevSolid->getNameInDocument()); - } - Gui::Selection().clearSelection(); - Gui::Selection().addSelectionGate - (new ReferenceSelection(prevSolid, edge, face, planar)); - } else { - Gui::Selection().rmvSelectionGate(); - Gui::Document* doc = Gui::Application::Instance->activeDocument(); - if (doc) { - if (pcSketchBased) + if (prevSolid) + doc->setShow(prevSolid->getNameInDocument()); + } + Gui::Selection().clearSelection(); + Gui::Selection().addSelectionGate + (new ReferenceSelection(prevSolid, edge, face, planar)); + } else { + Gui::Selection().rmvSelectionGate(); + Gui::Document* doc = vp->getDocument(); + if (doc) { doc->setShow(pcSketchBased->getNameInDocument()); - if (prevSolid) - doc->setHide(prevSolid->getNameInDocument()); + if (prevSolid) + doc->setHide(prevSolid->getNameInDocument()); + } } } } @@ -129,7 +128,7 @@ void TaskSketchBasedParameters::exitSelectionMode() const QByteArray TaskSketchBasedParameters::onFaceName(const QString& text) { - if (text.length() == 0) + if (text.isEmpty()) return QByteArray(); QStringList parts = text.split(QChar::fromLatin1(':')); @@ -141,6 +140,9 @@ const QByteArray TaskSketchBasedParameters::onFaceName(const QString& text) return QByteArray(); PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); + if (!activeBody) + return QByteArray(); + if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { // everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree) return QByteArray(); diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index a570e8fa7..1e1df1c74 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -65,8 +65,9 @@ TaskTransformedParameters::TaskTransformedParameters(ViewProviderTransformed *Tr QString::fromLatin1((TransformedView->featureName + " parameters").c_str()), true, parent), + proxy(nullptr), TransformedView(TransformedView), - parentTask(NULL), + parentTask(nullptr), insideMultiTransform(false), blockUpdate(false) { @@ -75,7 +76,8 @@ TaskTransformedParameters::TaskTransformedParameters(ViewProviderTransformed *Tr TaskTransformedParameters::TaskTransformedParameters(TaskMultiTransformParameters *parentTask) : TaskBox(QPixmap(), tr(""), true, parentTask), - TransformedView(NULL), + proxy(nullptr), + TransformedView(nullptr), parentTask(parentTask), insideMultiTransform(true), blockUpdate(false) @@ -345,7 +347,7 @@ void TaskTransformedParameters::addReferenceSelectionGate(bool edge, bool face) //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskDlgTransformedParameters::TaskDlgTransformedParameters(ViewProviderTransformed *TransformedView_) - : TaskDlgFeatureParameters(TransformedView_) + : TaskDlgFeatureParameters(TransformedView_), parameter(0) { assert(vp); message = new TaskTransformedMessages(getTransformedView()); diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 79dc32377..8b7e21f25 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -59,23 +59,22 @@ PartDesign::Body *getBody(bool messageIfNot) PartDesign::Body * activeBody = nullptr; Gui::MDIView *activeView = Gui::Application::Instance->activeView(); - if ( PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { - - if (activeView) { + if (activeView) { + if ( PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { activeBody = activeView->getActiveObject(PDBODYKEY); - } - if (!activeBody && messageIfNot) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), - QObject::tr("In order to use PartDesign you need an active Body object in the document. " - "Please make one active (double click) or create one. If you have a legacy document " - "with PartDesign objects without Body, use the transfer function in " - "PartDesign to put them into a Body." - )); + if (!activeBody && messageIfNot) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), + QObject::tr("In order to use PartDesign you need an active Body object in the document. " + "Please make one active (double click) or create one. If you have a legacy document " + "with PartDesign objects without Body, use the transfer function in " + "PartDesign to put them into a Body." + )); + } } } - return activeBody; + return activeBody; } PartDesign::Body *getBodyFor(const App::DocumentObject* obj, bool messageIfNot) diff --git a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp index 2e3af7405..66c61b122 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp @@ -65,11 +65,9 @@ ViewProviderPrimitive::~ViewProviderPrimitive() } void ViewProviderPrimitive::attach(App::DocumentObject* obj) { - ViewProviderAddSub::attach(obj); } - bool ViewProviderPrimitive::setEdit(int ModNum) { if (ModNum == ViewProvider::Default ) { @@ -80,8 +78,6 @@ bool ViewProviderPrimitive::setEdit(int ModNum) // the task panel Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); TaskPrimitiveParameters *primitiveDlg = qobject_cast(dlg); - if (primitiveDlg) - primitiveDlg = 0; // another pad left open its task panel if (dlg && !primitiveDlg) { QMessageBox msgBox; msgBox.setText(QObject::tr("A dialog is already open in the task panel")); @@ -102,6 +98,7 @@ bool ViewProviderPrimitive::setEdit(int ModNum) oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench"); // start the edit dialog + // another pad left open its task panel if (primitiveDlg) Gui::Control().showDialog(primitiveDlg); else @@ -119,14 +116,10 @@ void ViewProviderPrimitive::unsetEdit(int ModNum) { } void ViewProviderPrimitive::updateData(const App::Property* p) { - PartDesignGui::ViewProviderAddSub::updateData(p); } - - std::vector< App::DocumentObject* > ViewProviderPrimitive::claimChildren(void) const { - std::vector< App::DocumentObject* > vec; vec.push_back(static_cast(getObject())->CoordinateSystem.getValue()); @@ -134,42 +127,41 @@ std::vector< App::DocumentObject* > ViewProviderPrimitive::claimChildren(void) c } QIcon ViewProviderPrimitive::getIcon(void) const { - + QString str = QString::fromLatin1("PartDesign_"); auto* prim = static_cast(getObject()); if(prim->getAddSubType() == PartDesign::FeatureAddSub::Additive) str += QString::fromLatin1("Additive_"); else str += QString::fromLatin1("Subtractive_"); - + switch(prim->getPrimitiveType()) { - - case PartDesign::FeaturePrimitive::Box: - str += QString::fromLatin1("Box"); - break; - case PartDesign::FeaturePrimitive::Cylinder: - str += QString::fromLatin1("Cylinder"); - break; - case PartDesign::FeaturePrimitive::Sphere: - str += QString::fromLatin1("Sphere"); - break; - case PartDesign::FeaturePrimitive::Cone: - str += QString::fromLatin1("Cone"); - break; - case PartDesign::FeaturePrimitive::Ellipsoid: - str += QString::fromLatin1("Ellipsoid"); - break; - case PartDesign::FeaturePrimitive::Torus: - str += QString::fromLatin1("Torus"); - break; - case PartDesign::FeaturePrimitive::Prism: - str += QString::fromLatin1("Prism"); - break; - case PartDesign::FeaturePrimitive::Wedge: - str += QString::fromLatin1("Wedge"); - break; + case PartDesign::FeaturePrimitive::Box: + str += QString::fromLatin1("Box"); + break; + case PartDesign::FeaturePrimitive::Cylinder: + str += QString::fromLatin1("Cylinder"); + break; + case PartDesign::FeaturePrimitive::Sphere: + str += QString::fromLatin1("Sphere"); + break; + case PartDesign::FeaturePrimitive::Cone: + str += QString::fromLatin1("Cone"); + break; + case PartDesign::FeaturePrimitive::Ellipsoid: + str += QString::fromLatin1("Ellipsoid"); + break; + case PartDesign::FeaturePrimitive::Torus: + str += QString::fromLatin1("Torus"); + break; + case PartDesign::FeaturePrimitive::Prism: + str += QString::fromLatin1("Prism"); + break; + case PartDesign::FeaturePrimitive::Wedge: + str += QString::fromLatin1("Wedge"); + break; } - + str += QString::fromLatin1(".svg"); return Gui::BitmapFactory().pixmap(str.toStdString().c_str()); } diff --git a/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp b/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp index 0c86910d2..308e465be 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp @@ -81,15 +81,12 @@ ViewProviderShapeBinder::~ViewProviderShapeBinder() bool ViewProviderShapeBinder::setEdit(int ModNum) { // TODO Share code with other view providers (2015-09-11, Fat-Zer) - if (ModNum == ViewProvider::Default || ModNum == 1 ) { - + if (ModNum == ViewProvider::Default || ModNum == 1) { // When double-clicking on the item for this pad the // object unsets and sets its edit mode without closing // the task panel Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); TaskDlgShapeBinder *sbDlg = qobject_cast(dlg); - if (sbDlg) - sbDlg = 0; // another pad left open its task panel if (dlg && !sbDlg) { QMessageBox msgBox; msgBox.setText(QObject::tr("A dialog is already open in the task panel")); @@ -107,6 +104,7 @@ bool ViewProviderShapeBinder::setEdit(int ModNum) { Gui::Selection().clearSelection(); // start the edit dialog + // another pad left open its task panel if (sbDlg) Gui::Control().showDialog(sbDlg); else diff --git a/src/Mod/PartDesign/Gui/ViewProviderTransformed.h b/src/Mod/PartDesign/Gui/ViewProviderTransformed.h index 962676cc1..95713f197 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderTransformed.h +++ b/src/Mod/PartDesign/Gui/ViewProviderTransformed.h @@ -37,7 +37,7 @@ class PartDesignGuiExport ViewProviderTransformed : public ViewProvider public: /// constructor ViewProviderTransformed() - : featureName("undefined") {} + : featureName("undefined"), pcRejectedRoot(nullptr) {} /// destructor virtual ~ViewProviderTransformed() {}