]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#2084 Unknown error when trim: Do not copyAttribute
authornds <nds@opencascade.com>
Tue, 4 Apr 2017 12:48:25 +0000 (15:48 +0300)
committernds <nds@opencascade.com>
Tue, 4 Apr 2017 12:48:44 +0000 (15:48 +0300)
src/ModuleBase/ModuleBase_IModule.cpp
src/PartSet/PartSet_SketcherReentrantMgr.cpp
src/SketchPlugin/SketchPlugin_Trim.cpp

index 39f9abc799b7e20de9e6ba9aa09aba247b15d782..fe5bff496eceae0bfe665b358a8a558a6590a0d7 100644 (file)
@@ -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);
+          }
         }
       }
     }
index b9c92f940c6a08d417f4ea475cb1d873f8698882..41ff190453e0825bd39902dda425c6d16252b990 100644 (file)
@@ -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<ModelAPI_AttributeReference> 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<ModelAPI_AttributeReference> aRefPreviewAttr =
+    /*std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
                       std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
                       theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
     std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
                         std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
                         theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
-    aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
+    aNRefPreviewAttr->setValue(aRefPreviewAttr->value());*/
 
     /*std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
                       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
@@ -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<GeomDataAPI_Point2D> aPointPreviewAttr =
+    /*std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
                       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
                       theSourceFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
     std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
                       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
                       theNewFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
     aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
-
-    aChanged = true;
+    */
+    //aChanged = true;
   }
   return aChanged;
 }
index 4e60668376998ee0c60c7a55317efdd15f1b99d3..538f1b937dded160610dd96f491ebd9550bdf7e9 100644 (file)
@@ -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<ModelAPI_AttributeReference>(
@@ -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_ptr<Events_Message
 #ifdef DEBUG_TRIM_METHODS
   std::cout << "SketchPlugin_Trim::processEvent:" << data()->name() << std::endl;
 #endif
-
   std::string aFilledAttributeName;
 
   std::shared_ptr<ModelAPI_EventReentrantMessage> aMessage =
@@ -491,34 +494,39 @@ std::string SketchPlugin_Trim::processEvent(const std::shared_ptr<Events_Message
     std::shared_ptr<GeomAPI_Pnt2d> aPoint = aMessage->clickedPoint();
 
     if (anObject.get() && aPoint.get()) {
-      std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
-                            std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                            data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
-      std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
-                            std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
-                            data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
-      aRefSelectedAttr->setValue(anObject);
-      aRefPreviewAttr->setValue(anObject);
-
-      std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
-                            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                            data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
-      std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
-                            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-                            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<GeomShapePtr>& aShapes = myCashedShapes[anObject];
+      if (aShapes.size() > 1) {
+        std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
+                              std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+                              data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
+        std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
+                              std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+                              data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
+        aRefSelectedAttr->setValue(anObject);
+        aRefPreviewAttr->setValue(anObject);
+
+        std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
+                              std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                              data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
+        std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
+                              std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+                              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;