From cbdf04f765bf1eef0e9b91755d69732d5a1df511 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 17 Apr 2015 14:52:58 +0300 Subject: [PATCH] External edges for mirror --- .../ModuleBase_WidgetMultiSelector.h | 2 +- src/PartSet/PartSet_ExternalObjectsMgr.cpp | 73 +++++++++++++++++++ src/PartSet/PartSet_ExternalObjectsMgr.h | 19 +++++ src/PartSet/PartSet_WidgetMultiSelector.cpp | 37 +++++++++- src/PartSet/PartSet_WidgetMultiSelector.h | 11 +++ .../SketchPlugin_ConstraintMirror.cpp | 2 - 6 files changed, 139 insertions(+), 5 deletions(-) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 9fc28310e..cc702f6a1 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -81,7 +81,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge void onSelectionTypeChanged(); /// Slot is called on selection changed - void onSelectionChanged(); + virtual void onSelectionChanged(); protected slots: /// Slot for copy command in a list pop-up menu diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.cpp b/src/PartSet/PartSet_ExternalObjectsMgr.cpp index 2ba5b8668..b12f92b5f 100644 --- a/src/PartSet/PartSet_ExternalObjectsMgr.cpp +++ b/src/PartSet/PartSet_ExternalObjectsMgr.cpp @@ -37,6 +37,24 @@ ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelecte return aSelectedObject; } +//******************************************************************** +ObjectPtr PartSet_ExternalObjectsMgr::externalObjectValidated(const ObjectPtr& theSelectedObject, + const GeomShapePtr& theShape, + const CompositeFeaturePtr& theSketch) +{ + // TODO(nds): unite with externalObject() + ObjectPtr aSelectedObject = PartSet_Tools::findFixedObjectByExternal(theShape->impl(), + theSelectedObject, theSketch); + if (!aSelectedObject.get()) { + // Processing of external (non-sketch) object + aSelectedObject = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), + theSelectedObject, theSketch); + if (aSelectedObject.get()) + myExternalObjectValidated = aSelectedObject; + } + return aSelectedObject; +} + //******************************************************************** void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch, const FeaturePtr& theFeature) @@ -61,6 +79,61 @@ void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSk XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures); } } + //removeExternalObject(anObject, theSketch, theFeature); } myExternalObjects.clear(); } + +//******************************************************************** +void PartSet_ExternalObjectsMgr::removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects, + const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature) +{ + /* + // TODO(nds): unite with removeExternal(), remove parameters + QObjectPtrList aUsedExternalObjects; + + QObjectPtrList::const_iterator anIt = myExternalObjects.begin(), aLast = myExternalObjects.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + if (theIgnoreObjects.contains(anObject)) + aUsedExternalObjects.append(anObject); + else + removeExternalObject(anObject, theSketch, theFeature); + }*/ + myExternalObjects.clear(); + //if (!aUsedExternalObjects.empty()) + // myExternalObjects = aUsedExternalObjects; +} + +//******************************************************************** +void PartSet_ExternalObjectsMgr::removeExternalValidated(const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature) +{ + // TODO(nds): unite with removeExternal(), remove parameters + removeExternalObject(myExternalObjectValidated, theSketch, theFeature); + myExternalObjectValidated = NULL; +} + +void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject, + const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature) +{ + if (theObject.get()) { + DocumentPtr aDoc = theObject->document(); + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + if (aFeature.get() != NULL) { + QObjectPtrList anObjects; + anObjects.append(aFeature); + // the external feature should be removed with all references, sketch feature should be ignored + std::set anIgnoredFeatures; + anIgnoredFeatures.insert(theSketch); + // the current feature should be ignored, because it can use the external feature in the + // attributes and, therefore have a references to it. So, the delete functionality tries + // to delete this feature. Test case is creation of a constraint on external point, + // use in this control after an external point, the point of the sketch. + anIgnoredFeatures.insert(theFeature); + XGUI_Workshop::deleteFeatures(anObjects, anIgnoredFeatures); + } + } +} diff --git a/src/PartSet/PartSet_ExternalObjectsMgr.h b/src/PartSet/PartSet_ExternalObjectsMgr.h index 6451751de..45f89a84c 100644 --- a/src/PartSet/PartSet_ExternalObjectsMgr.h +++ b/src/PartSet/PartSet_ExternalObjectsMgr.h @@ -44,16 +44,35 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr ObjectPtr externalObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape, const CompositeFeaturePtr& theSketch); + ObjectPtr externalObjectValidated(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape, + const CompositeFeaturePtr& theSketch); + + // Removes the external presentation from the model /// \param theSketch a current sketch /// \param theFeature a current feature void removeExternal(const CompositeFeaturePtr& theSketch, const FeaturePtr& theFeature); + void removeExternalValidated(const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature); + + void removeUnusedExternalObjects(const QObjectPtrList& theIgnoreObjects, + const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature); + +protected: + void removeExternalObject(const ObjectPtr& theObject, + const CompositeFeaturePtr& theSketch, + const FeaturePtr& theFeature); + protected: /// An external object QObjectPtrList myExternalObjects; + /// An external object + ObjectPtr myExternalObjectValidated; + /// Boolean value about the neccessity of the external object use bool myUseExternal; }; diff --git a/src/PartSet/PartSet_WidgetMultiSelector.cpp b/src/PartSet/PartSet_WidgetMultiSelector.cpp index 1c046be78..43f066ea2 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.cpp +++ b/src/PartSet/PartSet_WidgetMultiSelector.cpp @@ -41,11 +41,41 @@ PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector() delete myExternalObjectMgr; } +//******************************************************************** +void PartSet_WidgetMultiSelector::onSelectionChanged() +{ + ModuleBase_WidgetMultiSelector::onSelectionChanged(); + // TODO(nds): unite with externalObject(), remove parameters + //myFeature->execute(); + + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(aData->attribute(attributeID())); + + QObjectPtrList aListOfAttributeObjects; + for (int i = 0; i < aSelectionListAttr->size(); i++) { + AttributeSelectionPtr anAttr = aSelectionListAttr->value(i); + aListOfAttributeObjects.append(anAttr->context()); + } + + myExternalObjectMgr->removeUnusedExternalObjects(aListOfAttributeObjects, sketch(), myFeature); +} + +//******************************************************************** +void PartSet_WidgetMultiSelector::storeAttributeValue() +{ + myIsInVaildate = true; + ModuleBase_WidgetMultiSelector::storeAttributeValue(); + +} + //******************************************************************** void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid) { + myIsInVaildate = false; ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid); - myExternalObjectMgr->removeExternal(sketch(), myFeature); + + myExternalObjectMgr->removeExternalValidated(sketch(), myFeature); } //******************************************************************** @@ -126,7 +156,10 @@ bool PartSet_WidgetMultiSelector::setObject(const ObjectPtr& theSelectedObject, return false; if (aSPFeature.get() == NULL && aShape.get() != NULL && !aShape->isNull() && myExternalObjectMgr->useExternal()) { - aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch()); + if (myIsInVaildate) + aSelectedObject = myExternalObjectMgr->externalObjectValidated(theSelectedObject, theShape, sketch()); + else + aSelectedObject = myExternalObjectMgr->externalObject(theSelectedObject, theShape, sketch()); } diff --git a/src/PartSet/PartSet_WidgetMultiSelector.h b/src/PartSet/PartSet_WidgetMultiSelector.h index 0bb999f08..ba7ffea54 100644 --- a/src/PartSet/PartSet_WidgetMultiSelector.h +++ b/src/PartSet/PartSet_WidgetMultiSelector.h @@ -47,7 +47,16 @@ Q_OBJECT /// \param theOwner a selected owner virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); +public slots: + /// Slot is called on selection changed + virtual void onSelectionChanged(); + protected: + /// Creates a backup of the current values of the attribute + /// It should be realized in the specific widget because of different + /// parameters of the current attribute + virtual void storeAttributeValue(); + /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different /// parameters of the current attribute @@ -65,6 +74,8 @@ protected: PartSet_ExternalObjectsMgr* myExternalObjectMgr; /// Pointer to a sketch CompositeFeaturePtr mySketch; + + bool myIsInVaildate; }; #endif \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index f28a09516..d3ba226f6 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -43,8 +43,6 @@ void SketchPlugin_ConstraintMirror::execute() { AttributeSelectionListPtr aMirrorObjectRefs = selectionList(SketchPlugin_ConstraintMirror::MIRROR_LIST_ID()); - if (!aMirrorObjectRefs->isInitialized()) - return; std::shared_ptr aData = data(); AttributeRefListPtr aRefListOfShapes = std::dynamic_pointer_cast( -- 2.39.2