From 5a3f79d60c67c95941f11c868b377046d18d4e25 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 4 Apr 2017 15:48:25 +0300 Subject: [PATCH] #2084 Unknown error when trim: Do not copyAttribute --- src/ModuleBase/ModuleBase_IModule.cpp | 9 +-- src/PartSet/PartSet_SketcherReentrantMgr.cpp | 27 ++++---- src/SketchPlugin/SketchPlugin_Trim.cpp | 70 +++++++++++--------- 3 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 39f9abc79..fe5bff496 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -114,10 +114,11 @@ void ModuleBase_IModule::launchOperation(const QString& theCmdId, if (aMessage.get()) { ModuleBase_IPropertyPanel* aPanel = workshop()->propertyPanel(); std::string aPrevAttribute = aReentrantFeature->processEvent(aMessage); - workshop()->errorMgr()->updateActions(aFeature); - - ModuleBase_ModelWidget* aPrevWidget = aPanel->modelWidget(aPrevAttribute); - aPanel->activateNextWidget(aPrevWidget); + if (!aPrevAttribute.empty()) { + workshop()->errorMgr()->updateActions(aFeature); + ModuleBase_ModelWidget* aPrevWidget = aPanel->modelWidget(aPrevAttribute); + aPanel->activateNextWidget(aPrevWidget); + } } } } diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.cpp b/src/PartSet/PartSet_SketcherReentrantMgr.cpp index b9c92f940..41ff19045 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReentrantMgr.cpp @@ -152,17 +152,16 @@ bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* the ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel(); FeaturePtr aCurrentFeature = aFOperation->feature(); - bool isLineFeature = false, isArcFeature = false; + bool isLineFeature = false, isReentrantArcFeature = false; std::string anAttributeOnStart; if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) { anAttributeOnStart = SketchPlugin_Line::START_ID(); isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart; } else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) { - anAttributeOnStart = SketchPlugin_MacroArc::TANGENT_POINT_ID(); - isArcFeature = anActiveWidget->attributeID() == anAttributeOnStart; + isReentrantArcFeature = true; } - bool aCanBeActivatedByMove = isLineFeature || isArcFeature; + bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature; if (aCanBeActivatedByMove) { /// before restarting of operation we need to clear selection, as it may take part in /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed @@ -690,16 +689,16 @@ bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& th AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId); if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value()); - //ModuleBase_Tools::flushUpdated(theNewFeature); - aChanged = true;*/ + //ModuleBase_Tools::flushUpdated(theNewFeature);*/ + //aChanged = true; } else if (aFeatureKind == SketchPlugin_MacroArc::ID()) { // set arc type - std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE(); + /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE(); AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId); AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId); if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes - aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value()); + aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/ //// if the arc is tangent, set coincidence to end point of the previous arc //std::string anArcType = aSourceFeatureTypeAttr->value(); //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) { @@ -720,7 +719,7 @@ bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& th //} //ModuleBase_Tools::flushUpdated(theNewFeature); - aChanged = true; + //aChanged = true; } else if (aFeatureKind == SketchPlugin_Trim::ID()) { /*std::shared_ptr aRefSelectedAttr = @@ -731,13 +730,13 @@ bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& th theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); aNRefSelectedAttr->setValue(aRefSelectedAttr->value());*/ - std::shared_ptr aRefPreviewAttr = + /*std::shared_ptr aRefPreviewAttr = std::dynamic_pointer_cast( theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); std::shared_ptr aNRefPreviewAttr = std::dynamic_pointer_cast( theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); - aNRefPreviewAttr->setValue(aRefPreviewAttr->value()); + aNRefPreviewAttr->setValue(aRefPreviewAttr->value());*/ /*std::shared_ptr aPointSelectedAttr = std::dynamic_pointer_cast( @@ -747,15 +746,15 @@ bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& th theNewFeature->data()->attribute(SketchPlugin_Trim::SELECTED_POINT())); aNPointSelectedAttr->setValue(aPointSelectedAttr->x(), aPointSelectedAttr->y()); */ - std::shared_ptr aPointPreviewAttr = + /*std::shared_ptr aPointPreviewAttr = std::dynamic_pointer_cast( theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); std::shared_ptr aNPointPreviewAttr = std::dynamic_pointer_cast( theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y()); - - aChanged = true; + */ + //aChanged = true; } return aChanged; } diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index 4e6066837..538f1b937 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -189,8 +189,10 @@ void SketchPlugin_Trim::execute() #endif SketchPlugin_Sketch* aSketch = sketch(); - if (!aSketch) + if (!aSketch) { + setError("Error: Sketch object is empty."); return; + } // Check the base objects are initialized. AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( @@ -200,8 +202,10 @@ void SketchPlugin_Trim::execute() return; } ObjectPtr aBaseObject = aBaseObjectAttr->value(); - if (!aBaseObject.get()) + if (!aBaseObject.get()) { + setError("Error: Base object is not initialized."); return; + } FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); /// Remove reference of this feature to feature used in preview, it is not necessary anymore @@ -481,7 +485,6 @@ std::string SketchPlugin_Trim::processEvent(const std::shared_ptrname() << std::endl; #endif - std::string aFilledAttributeName; std::shared_ptr aMessage = @@ -491,34 +494,39 @@ std::string SketchPlugin_Trim::processEvent(const std::shared_ptr aPoint = aMessage->clickedPoint(); if (anObject.get() && aPoint.get()) { - std::shared_ptr aRefSelectedAttr = - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); - std::shared_ptr aRefPreviewAttr = - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); - aRefSelectedAttr->setValue(anObject); - aRefPreviewAttr->setValue(anObject); - - std::shared_ptr aPointSelectedAttr = - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::SELECTED_POINT())); - std::shared_ptr aPointPreviewAttr = - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); - aPointSelectedAttr->setValue(aPoint); - aPointPreviewAttr->setValue(aPoint); - - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - - GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT()); -#ifdef DEBUG_TRIM_METHODS - if (!aSelectedShape.get()) - std::cout << "Set empty selected object" << std::endl; - else - std::cout << "Set shape with ShapeType: " << aSelectedShape->shapeTypeStr() << std::endl; -#endif - aFilledAttributeName = SketchPlugin_Trim::SELECTED_OBJECT(); + if (myCashedShapes.find(anObject) == myCashedShapes.end()) + fillObjectShapes(anObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints); + const std::set& aShapes = myCashedShapes[anObject]; + if (aShapes.size() > 1) { + std::shared_ptr aRefSelectedAttr = + std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT())); + std::shared_ptr aRefPreviewAttr = + std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT())); + aRefSelectedAttr->setValue(anObject); + aRefPreviewAttr->setValue(anObject); + + std::shared_ptr aPointSelectedAttr = + std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Trim::SELECTED_POINT())); + std::shared_ptr aPointPreviewAttr = + std::dynamic_pointer_cast( + data()->attribute(SketchPlugin_Trim::PREVIEW_POINT())); + aPointSelectedAttr->setValue(aPoint); + aPointPreviewAttr->setValue(aPoint); + + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); + + GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT()); + #ifdef DEBUG_TRIM_METHODS + if (!aSelectedShape.get()) + std::cout << "Set empty selected object" << std::endl; + else + std::cout << "Set shape with ShapeType: " << aSelectedShape->shapeTypeStr() << std::endl; + #endif + aFilledAttributeName = SketchPlugin_Trim::SELECTED_OBJECT(); + } } } return aFilledAttributeName; -- 2.39.2