Salome HOME
Update constraint Mirror.
authorazv <azv@opencascade.com>
Wed, 8 Apr 2015 13:57:25 +0000 (16:57 +0300)
committerazv <azv@opencascade.com>
Wed, 8 Apr 2015 13:58:04 +0000 (16:58 +0300)
Fix a problem with Coincidence

src/Model/Model_AttributeRefList.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_AttributeSelectionList.cpp
src/ModelAPI/ModelAPI_Attribute.h
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index c09190f3326da11cd0057ac0236d4397780762c9..13233fb9c4e0128becbf03d324014051ceb4539e 100644 (file)
@@ -29,6 +29,7 @@ void Model_AttributeRefList::remove(ObjectPtr theObject)
   if (theObject.get() != NULL) {
     aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
     myRef->Remove(aData->label().Father());
+    REMOVE_BACK_REF(theObject);
   }
   else { // in case of empty object remove, the first empty object is removed from the list
     std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
index 3e23333451931c81706be68835312774179d2a04..b522b90a14129a9ab8c084943d5a69adce963db2 100644 (file)
@@ -171,6 +171,12 @@ Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
   myIsInitialized = myRef.isInitialized();
 }
 
+void Model_AttributeSelection::setID(const std::string theID)
+{
+  myRef.setID(theID);
+  ModelAPI_AttributeSelection::setID(theID);
+}
+
 ResultPtr Model_AttributeSelection::context() {
   return std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
 }
index 8708c136dc932defde1ecfba2c0761475841ee7f..22aaf8d9f9b831476ba6d1c63d47701f7570f6b3 100644 (file)
@@ -71,6 +71,9 @@ protected:
   /// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
   TDF_LabelMap& scope();
 
+  /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
+  MODELAPI_EXPORT virtual void setID(const std::string theID);
+
   friend class Model_Data;
   friend class Model_AttributeSelectionList;
 };
index 24a9efca5308d5684d3030a0b55c6ac5d4fd8f54..79eb5c714e12ee2e5565c209dfb271f3d793b389 100644 (file)
@@ -39,6 +39,7 @@ void Model_AttributeSelectionList::append(
   if (owner()) {
     aNewAttr->setObject(owner());
   }
+  aNewAttr->setID(id());
   mySize->Set(aNewTag);
   aNewAttr->setValue(theContext, theSubShape);
   owner()->data()->sendAttributeUpdated(this);
index 1892b77bc8c5687367d091a559fc67a7451450b5..e3b1b056df9514052fe2bfebd6f256c5320b56e9 100644 (file)
@@ -77,7 +77,7 @@ class ModelAPI_Attribute
   MODELAPI_EXPORT ModelAPI_Attribute();
 
   /// Sets the ID of the attribute in Data (called from Data)
-  MODELAPI_EXPORT void setID(const std::string theID);
+  MODELAPI_EXPORT virtual void setID(const std::string theID);
 
   friend class Model_Data;
 };
index e92cdb8c47472ae37d3726b24434f64d4743ca87..91a92ce7b2f89dd8498c70cd8c2b9066af0a7e37 100644 (file)
@@ -59,6 +59,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                               new SketchPlugin_NotFixedValidator);
   aFactory->registerValidator("SketchPlugin_EqualAttr",
                               new SketchPlugin_EqualAttrValidator);
+  aFactory->registerValidator("SketchPlugin_MirrorAttr",
+                              new SketchPlugin_MirrorAttrValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 95da79b9513deced964b1fd618ad7cab8ef9f6d2..72f0b61d1cb6872e656d70b75d631b8353ab22c1 100644 (file)
@@ -18,6 +18,8 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_Session.h>
 
 #include <GeomValidators_Edge.h>
@@ -211,3 +213,26 @@ bool SketchPlugin_EqualAttrValidator::isValid(
   return true;
 }
 
+bool SketchPlugin_MirrorAttrValidator::isValid(
+  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeSelectionListPtr aSelAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  if (!aSelAttr)
+    return false;
+
+  AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+      aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
+  std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
+
+  for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> aSelect = aSelAttr->value(anInd);
+    std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
+    for (; aMirIter != aMirroredObjects.end(); aMirIter++)
+      if (aSelect->context() == *aMirIter)
+        return false;
+  }
+  return true;
+}
+
index 47df3706156129b4cfacac9f4891d6bc0b733bc9..e4f6d36d6904eefabf32e44a0b30e4f9ade5e169 100644 (file)
@@ -76,5 +76,21 @@ class SketchPlugin_EqualAttrValidator : public ModelAPI_AttributeValidator
                        const std::list<std::string>& theArguments) const;
 };
 
+/**\class SketchPlugin_MirrorAttrValidator
+ * \ingroup Validators
+ * \brief Validator for the mirror constraint input.
+ *
+ * It checks that attributes of the Mirror constraint are correct.
+ */
+class SketchPlugin_MirrorAttrValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute (not used)
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const;
+};
+
 
 #endif
index 323120ce97e118b7ba7a2a910aaef4489415b097..208f2e689f521c6b281694f73af5537b3ba3339e 100644 (file)
             label="List of objects"
             tooltip="Select list of mirroring objects"
             type_choice="Edges">
+            <validator id="SketchPlugin_MirrorAttr" />
         </multi_selector>
       </feature>
     </group>
index 1172988cba921d4ba5e83eab6c9d0627ca88789f..2ae6bf381b4922a07398f41495e7f3254fc3fd12 100644 (file)
@@ -202,6 +202,6 @@ bool SketchSolver_ConstraintCoincidence::remove(ConstraintPtr theConstraint)
     }
     anExtraIt++;
   }
-  return isFullyRemoved;
+  return mySlvsConstraints.empty();
 }
 
index d4a5171322ad5701bd990264cbe94c8185c8c901..1690d7d561d37b5a4040b46b3ba2583fe7522168 100644 (file)
@@ -151,13 +151,19 @@ bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
       if (anEntIter->distance == theEntityID)
         return false;
     }
+    std::set<Slvs_hEntity> anEntAndSubs;
+    anEntAndSubs.insert(theEntityID);
+    for (int i = 0; i < 4; i++)
+      if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
+        anEntAndSubs.insert(myEntities[aPos].point[i]);
+
     std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
     for (; aConstrIter != myConstraints.end(); aConstrIter++) {
       Slvs_hEntity anEntIDs[6] = {aConstrIter->ptA, aConstrIter->ptB,
           aConstrIter->entityA, aConstrIter->entityB,
           aConstrIter->entityC, aConstrIter->entityD};
       for (int i = 0; i < 6; i++)
-        if (anEntIDs[i] == theEntityID)
+        if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
           return false;
     }
     // The entity is not used, remove it and its parameters