Salome HOME
Fix the problem with renamed sketch edges vertices selection (the stator_ermes case)
authormpv <mpv@opencascade.com>
Wed, 31 Oct 2018 14:44:44 +0000 (17:44 +0300)
committermpv <mpv@opencascade.com>
Mon, 19 Nov 2018 08:45:52 +0000 (11:45 +0300)
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h

index 61b85dd89faf5c0698c9ac5628d8247e39bedd0c..0c07f092ea6e1976891b26ed2bc73645de9ccbc1 100644 (file)
@@ -705,6 +705,44 @@ bool Model_AttributeSelection::update()
   return setInvalidIfFalse(aSelLab, false); // unknown case
 }
 
+/// integer that contains the tag number of external construction shape naming
+static Standard_GUID kEXTERNAL_CONSTRUCTION_TAG("f7d0726f-e848-4d22-9101-def16d0eff2c");
+
+void Model_AttributeSelection::storeExternalConstruction(
+  const ResultConstructionPtr& theConstruction, const GeomShapePtr& theSubShape)
+{
+  std::string aName = namingName();
+  if (aName.empty()) // unknown error
+    return;
+  std::shared_ptr<Model_Document> aMyDoc =
+    std::dynamic_pointer_cast<Model_Document>(owner()->document());
+  TDF_Label anExternalLab = aMyDoc->extConstructionsLabel();
+  Handle(TDataStd_Integer) anExtTag;
+  if (selectionLabel().FindAttribute(kEXTERNAL_CONSTRUCTION_TAG, anExtTag)) {
+    anExternalLab = anExternalLab.FindChild(anExtTag->Get()); // use existing label
+  } else {
+    // search label with the same name
+    TDF_ChildIDIterator aNamesIter(anExternalLab, TDataStd_Name::GetID());
+    for(; aNamesIter.More(); aNamesIter.Next()) {
+      if (aName == TCollection_AsciiString(Handle(TDataStd_Name)::DownCast(
+        aNamesIter.Value())->Get()).ToCString()) {
+        anExternalLab = aNamesIter.Value()->Label();
+        break;
+      }
+    }
+    if (aNamesIter.More()) {
+    } else {
+      anExternalLab = anExternalLab.NewChild(); // create new label
+      TDataStd_Integer::Set(selectionLabel(), kEXTERNAL_CONSTRUCTION_TAG,
+        anExternalLab.Tag()); // store this tag in the data model
+    }
+  }
+  anExternalLab.ForgetAllAttributes();
+  TopoDS_Shape aSubShape = theSubShape->impl<TopoDS_Shape>();
+  TNaming_Builder aBuilder(anExternalLab);
+  aBuilder.Generated(aSubShape);
+}
+
 void Model_AttributeSelection::selectBody(
   const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape)
 {
@@ -755,10 +793,9 @@ void Model_AttributeSelection::selectBody(
         if (aFaceIndex >= 0) {
           TDataStd_Integer::Set(aSelLab, theSubShape->shapeType() == GeomAPI_Shape::FACE ?
             kEXT_SKETCH_FACE : kEXT_SKETCH_WIRE, aFaceIndex); // store index of the face
+          //storeExternalConstruction(aConstr, theSubShape);
           return;
         }
-      } else if (theSubShape->shapeType() == GeomAPI_Shape::WIRE) {
-
       } else if (theSubShape->shapeType() == GeomAPI_Shape::EDGE ||// sketch result edge (full one)
                  theSubShape->shapeType() == GeomAPI_Shape::VERTEX) { // or start/end vertex
         bool isVertex = theSubShape->shapeType() == GeomAPI_Shape::VERTEX;
@@ -1684,7 +1721,7 @@ bool Model_AttributeSelection::restoreContext(std::string theName,
             if ((*aRes)->data()->name() == aCompName) {
               theValue = std::dynamic_pointer_cast<Model_Data>((*aRes)->data())->shapeLab();
               break;
-            } else if (aCompName.find((*aRes)->data()->name()) != std::string::npos) {// sub-vertex
+            } else { // any sub-label because the sketch line may be renamed, but not sub-vertices
               TDF_Label aLab = std::dynamic_pointer_cast<Model_Data>((*aRes)->data())->shapeLab();
               TDF_ChildIDIterator aSubNames(aLab, TDataStd_Name::GetID());
               for(; aSubNames.More(); aSubNames.Next()) {
index 45b8ba7c24eb9aba51ef5bc0a89550b45ab56350..8759f8d58c7f7c66d3628fbc54872a14eed377f7 100644 (file)
@@ -31,6 +31,7 @@
 
 class Model_AttributeSelectionList;
 class Model_Document;
+class ModelAPI_ResultConstruction;
 
 /**\class Model_AttributeSelection
  * \ingroup DataModel
@@ -39,14 +40,14 @@ class Model_Document;
 class Model_AttributeSelection : public ModelAPI_AttributeSelection,
                                  public Selector_NameGenerator
 {
-  Model_AttributeReference myRef;  ///< The reference functionality reusage
+  Model_AttributeReference myRef;  ///< The reference functionality re-usage
   /// temporarily storages to avoid keeping in the data structure if not needed
   ResultPtr myTmpContext;
   /// temporarily storages to avoid keeping in the data structure if not needed
   std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
   /// temporarily storages to avoid keeping in the data structure if not needed
   CenterType myTmpCenterType;
-  /// Reference to the partent attribute, if any (to split selection compounds in issue 1799)
+  /// Reference to the parent attribute, if any (to split selection compounds in issue 1799)
   Model_AttributeSelectionList* myParent;
 
   std::shared_ptr<Model_Document> myRestoreDocument; // current document to restore by name
@@ -55,7 +56,7 @@ public:
   /// \param theContext object where the sub-shape was selected
   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
   /// \param theTemporarily if it is true, do not store and name the added in the data framework
-  ///           (used to remove immideately, without the following updates)
+  ///           (used to remove immediately, without the following updates)
   /// \returns true if attribute was updated
   MODEL_EXPORT virtual bool setValue(
     const ObjectPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
@@ -89,7 +90,7 @@ public:
   /// Sets the feature object
   MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
 
-  /// Updates the underlied selection due to the changes in the referenced objects
+  /// Updates the selection due to the changes in the referenced objects
   /// \returns false if update is failed
   MODEL_EXPORT virtual bool update();
 
@@ -107,7 +108,7 @@ public:
   /// NOTE: This method is opposite to Id() method.
   MODEL_EXPORT virtual void setId(int theID);
 
-  /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
+  /// Selects (i.e. creates Naming data structure) of sub-shape specified by textual name
   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
                                            const std::string& theSubShapeName);
 
@@ -121,7 +122,7 @@ public:
   /// Returns true if attribute was  initialized by some value
   MODEL_EXPORT virtual bool isInitialized();
 
-  /// Returns true if recomute of selection become impossible
+  /// Returns true if recompute of selection become impossible
   MODEL_EXPORT virtual bool isInvalid();
 
   /// Updates the arguments of selection if something was affected by creation
@@ -157,8 +158,11 @@ protected:
   /// Returns theType type of the center, or NOT_CENTER if it is not.
   std::shared_ptr<GeomAPI_Shape> internalValue(CenterType& theType);
 
-
-  /// Performs the selection for the body result (TNaming Selection)
+  /// stores the naming structure of external construction (sketch element) in the data
+  /// tree of this document with name equal to selection-name in external document
+  void storeExternalConstruction(
+    const std::shared_ptr<ModelAPI_ResultConstruction>& theConstruction,
+    const std::shared_ptr<GeomAPI_Shape>& theSubShape);
 
   /// Performs the selection for the body result (TNaming selection)
   virtual void selectBody(
@@ -168,7 +172,7 @@ protected:
   /// \param theContext the result - owner of the selection
   /// \param theSubShape selected shape
   /// \param theUpdate flag that shows that it must be just update, theShape is null
-  /// \returns true if eveything is selected correctly
+  /// \returns true if everything is selected correctly
   virtual bool selectPart(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
     const bool theUpdate = false);