]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
2D points selection in multi-translation/rotation : multi-translation: using ModelAPI...
authornds <nds@opencascade.com>
Fri, 18 Dec 2015 18:07:40 +0000 (21:07 +0300)
committernds <nds@opencascade.com>
Fri, 18 Dec 2015 18:08:03 +0000 (21:08 +0300)
src/GeomDataAPI/GeomDataAPI_Point2D.cpp
src/GeomDataAPI/GeomDataAPI_Point2D.h
src/SketchPlugin/SketchPlugin_MultiTranslation.cpp
src/SketchPlugin/SketchPlugin_MultiTranslation.h
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/CMakeLists.txt
src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp
src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h
src/SketchSolver/SketchSolver_IConstraintWrapper.h
src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp

index dd8b39ec5d5c6bae09e425d7ad6dba8a783f7aef..3a72ceaccd3d53910a260a9b58712746aaf62d31 100644 (file)
@@ -6,6 +6,7 @@
 
 
 #include <GeomDataAPI_Point2D.h>
+#include <ModelAPI_AttributeRefAttr.h>
 
 void GeomDataAPI_Point2D::move(const double theDeltaX, const double theDeltaY)
 {
@@ -17,6 +18,22 @@ std::string GeomDataAPI_Point2D::attributeType()
   return typeId();
 }
 
+std::shared_ptr<GeomDataAPI_Point2D> GeomDataAPI_Point2D::getPoint2D(
+                                  const DataPtr& theData, const std::string& theAttribute)
+{
+  std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+  if (!theData)
+    return aPointAttr;
+
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+                                 ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
+  if (anAttr && anAttr->attr()) {
+    aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+  }
+  return aPointAttr;
+}
+
+
 GeomDataAPI_Point2D::GeomDataAPI_Point2D()
 {
 }
index 7f67085e7dadd92981d7b5b9630a67f458101c35..633ef82559676141f9cf52c9d24ab22490fc8aa4 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <GeomDataAPI.h>
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
 
 #include <set>
 
@@ -82,6 +83,12 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute
   /// Returns the type of this class of attributes, not static method
   GEOMDATAAPI_EXPORT virtual std::string attributeType();
 
+  /// Returns this attribute from the data if it is possible
+  /// \param theData a model data
+  /// \param theAttribute an attribute index
+  static GEOMDATAAPI_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getPoint2D(const DataPtr& theData,
+                                                                  const std::string& theAttribute);
+
  protected:
   /// Objects are created for features automatically
   GEOMDATAAPI_EXPORT GeomDataAPI_Point2D();
index c94ae2dca77d3b18156a408b641293167339aa0b..2be40aecbec2e5f1541887614507d6abfdd6199d 100755 (executable)
@@ -14,6 +14,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
@@ -22,7 +23,6 @@
 #include <SketcherPrs_Factory.h>
 
 SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation()
-: myBlockValue(false)
 {
 }
 
@@ -30,10 +30,9 @@ void SketchPlugin_MultiTranslation::initAttributes()
 {
   data()->addAttribute(VALUE_TYPE(),   ModelAPI_AttributeString::typeId());
 
-  data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(START_FULL_POINT_ID(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId());
-  data()->addAttribute(END_FULL_POINT_ID(), GeomDataAPI_Point2D::typeId());
+  data()->addAttribute(START_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
+  data()->addAttribute(END_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
+
   data()->addAttribute(NUMBER_OF_OBJECTS_ID(), ModelAPI_AttributeInteger::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId());
   data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
@@ -56,30 +55,19 @@ void SketchPlugin_MultiTranslation::execute()
     return;
 
   // Calculate shift vector
-  std::shared_ptr<GeomDataAPI_Point2D> aStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      attribute(START_POINT_ID()));
-  std::shared_ptr<GeomDataAPI_Point2D> aEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-      attribute(END_POINT_ID()));
-  if (!aStart || !aEnd || !aStart->isInitialized() || !aEnd->isInitialized())
-    return;
-
-  if (attribute(END_POINT_ID())->isInitialized() && !attribute(END_FULL_POINT_ID())->isInitialized()) {
-    myBlockValue = true;
-    SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
-                                             attribute(END_FULL_POINT_ID()), aNbCopies, true);
-    myBlockValue = false;
-  }
-
+  AttributeRefAttrPtr aStartAttr = data()->refattr(START_POINT_ID());
+  AttributeRefAttrPtr anEndAttr = data()->refattr(END_POINT_ID());
 
-  // make a visible points
-  SketchPlugin_Sketch::createPoint2DResult(this, sketch(), START_POINT_ID(), 0);
+  if (!aStartAttr || !anEndAttr || !aStartAttr->isInitialized() || !anEndAttr->isInitialized())
+    return;
 
-  std::string aSecondPointAttributeID = END_POINT_ID();
-  AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE());
-  std::string aMethodType = aMethodTypeAttr->value();
-  if (aMethodType != "SingleValue")
-    aSecondPointAttributeID = END_FULL_POINT_ID();
-  SketchPlugin_Sketch::createPoint2DResult(this, sketch(), aSecondPointAttributeID, 1);
+  DataPtr aData = data();
+  std::shared_ptr<GeomDataAPI_Point2D> aStart = GeomDataAPI_Point2D::getPoint2D(aData,
+                                                                                START_POINT_ID());
+  std::shared_ptr<GeomDataAPI_Point2D> aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
+                                                                              END_POINT_ID());
+  if (!aStart || !aEnd)
+    return;
 
   std::shared_ptr<GeomAPI_XY> aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y()));
 
@@ -89,7 +77,6 @@ void SketchPlugin_MultiTranslation::execute()
   if (isUpdateFlushed)
     Events_Loop::loop()->setFlushed(anUpdateEvent, false);
 
-  std::shared_ptr<ModelAPI_Data> aData = data();
   AttributeRefListPtr aRefListOfShapes = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
   AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
@@ -273,63 +260,4 @@ void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID)
         data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear();
     }
   }
-  else if (theID == START_POINT_ID() && !myBlockValue) {
-    myBlockValue = true;
-    std::shared_ptr<GeomDataAPI_Point2D> aStartPoint = 
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aStartFullPoint = 
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_FULL_POINT_ID()));
-    aStartFullPoint->setValue(aStartPoint->pnt());
-    myBlockValue = false;
-  }
-  else if (theID == START_FULL_POINT_ID() && !myBlockValue) {
-    myBlockValue = true;
-    std::shared_ptr<GeomDataAPI_Point2D> aStartPoint = 
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aStartFullPoint = 
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_FULL_POINT_ID()));
-    aStartPoint->setValue(aStartFullPoint->pnt());
-    myBlockValue = false;
-  }
-  else if (theID == END_POINT_ID() && !myBlockValue) {
-    int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
-    if (aNbCopies > 0) {
-      myBlockValue = true;
-      SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
-                                               attribute(END_FULL_POINT_ID()), aNbCopies, true);
-      myBlockValue = false;
-      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-    }
-  }
-  else if (theID == END_FULL_POINT_ID() && !myBlockValue) {
-    int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
-    if (aNbCopies > 0) {
-      myBlockValue = true;
-      SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()),
-                                               attribute(END_POINT_ID()), aNbCopies, false);
-      myBlockValue = false;
-      Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-    }
-  }
-  else if (theID == NUMBER_OF_OBJECTS_ID()) {
-    if (attribute(NUMBER_OF_OBJECTS_ID())->isInitialized() &&
-        attribute(END_POINT_ID())->isInitialized() &&
-        attribute(VALUE_TYPE())->isInitialized()) {
-      AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE());
-      std::string aMethodType = aMethodTypeAttr->value();
-      int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
-      if (aNbCopies > 0) {
-        myBlockValue = true;
-        if (aMethodType == "SingleValue")
-          SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
-                                                   attribute(END_FULL_POINT_ID()), aNbCopies, true);
-        else {
-          SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()),
-                                                   attribute(END_POINT_ID()), aNbCopies, false);
-        }
-        myBlockValue = false;
-        Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-      }
-    }
-  }
 }
index b9d44214d7f980837841a29d2d67c69928de0600..7a3a78bc8b13ce7f94fe6e865c4c6c1822fd1150 100644 (file)
@@ -59,12 +59,6 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
     static const std::string MY_START_POINT_ID("MultiTranslationStartPoint");
     return MY_START_POINT_ID;
   }
-  /// Start point of translation
-  inline static const std::string& START_FULL_POINT_ID()
-  {
-    static const std::string MY_START_FULL_POINT_ID("MultiTranslationFullStartPoint");
-    return MY_START_FULL_POINT_ID;
-  }
 
   /// End point of translation
   inline static const std::string& END_POINT_ID()
@@ -72,12 +66,6 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
     static const std::string MY_END_POINT_ID("MultiTranslationEndPoint");
     return MY_END_POINT_ID;
   }
-  /// End point of translation
-  inline static const std::string& END_FULL_POINT_ID()
-  {
-    static const std::string MY_END_FULL_POINT_ID("MultiTranslationFullEndPoint");
-    return MY_END_FULL_POINT_ID;
-  }
 
   /// Total number of objects, initial and translated objects
   inline static const std::string& NUMBER_OF_OBJECTS_ID()
@@ -105,8 +93,6 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
 private:
   ObjectPtr copyFeature(ObjectPtr theObject);
 
-private:
-  bool myBlockValue; /// a boolean state to avoid recusive value change in attributeChanged
 };
 
 #endif
index 110b00461a1d3c2a8d621f9d332332a4bdb5539d..b38f14995ab3b4afba8aa7139b91e84a26e85f4a 100644 (file)
         <toolbox id="ValueType">
           <box id="SingleValue" title="Single value" icon=":icons/translate_32x32.png">
             <groupbox title="Direction">
-              <sketch-2dpoint_selector
-                  id="MultiTranslationStartPoint"
-                  title="Start point"
-                  tooltip="Start point of translation"/>
-              <sketch-2dpoint_selector
-                  id="MultiTranslationEndPoint"
-                  title="End point"
-                  tooltip="Final point of translation"/>
+              <sketch_shape_selector
+                    id="MultiTranslationStartPoint"
+                    label="Start point"
+                    tooltip="Start point of translation"
+                    shape_types="vertex">
+                <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+                <validator id="PartSet_DifferentObjects"/>
+                <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+              </sketch_shape_selector>
+              <sketch_shape_selector
+                    id="MultiTranslationEndPoint"
+                    label="End point"
+                    tooltip="Final point of translation"
+                    shape_types="vertex">
+                <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+                <validator id="PartSet_DifferentObjects"/>
+                <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+              </sketch_shape_selector>
             </groupbox>
           </box>
           <box id="FullValue" title="Full value" icon=":icons/translate_full_32x32.png">
             <groupbox title="Direction">
-              <sketch-2dpoint_selector
-                  id="MultiTranslationFullStartPoint"
-                  title="Start point"
-                  tooltip="Start point of translation"/>
-              <sketch-2dpoint_selector
-                  id="MultiTranslationFullEndPoint"
-                  title="End point"
-                  tooltip="Final point of translation"/>
+              <sketch_shape_selector
+                    id="MultiTranslationStartPoint"
+                    label="Start point"
+                    tooltip="Start point of translation"
+                    shape_types="vertex">
+                <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+                <validator id="PartSet_DifferentObjects"/>
+                <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+              </sketch_shape_selector>
+              <sketch_shape_selector
+                    id="MultiTranslationEndPoint"
+                    label="End point"
+                    tooltip="Final point of translation"
+                    shape_types="vertex">
+                <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+                <validator id="PartSet_DifferentObjects"/>
+                <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+              </sketch_shape_selector>
             </groupbox>
           </box>
         </toolbox>
         <integervalue id="MultiTranslationObjects"
             label="Total number of objects"
-            tooltip="Total number of objects" 
+            tooltip="Total number of objects"
             default="2" min="2" use_reset="false">
           <validator id="GeomValidators_Positive"/>
         </integervalue>
       </feature>
-      
+
       <!--  SketchMultiRotation  -->
       <feature
         id="SketchMultiRotation"
index 89ddc57102b2e5fa488f4fcdc839f9dfdbe6b6a2..c75eb93ba2cea6bf5c9ecbec8ee0526fd3b94c4f 100644 (file)
@@ -53,6 +53,7 @@ SET(PROJECT_LIBRARIES
     Events
     ModelAPI
     GeomAPI
+    GeomDataAPI
 )
 
 INCLUDE_DIRECTORIES(
index d6960c015b7996e1a380295b8960e25699567ae1..5a02f901c9a74e1b34f0e0d24d06ae59e45bcf23 100644 (file)
@@ -4,6 +4,9 @@
 
 #include <SketchPlugin_MultiTranslation.h>
 
+#include <ModelAPI_AttributeString.h>
+
+#include <GeomDataAPI_Point2D.h>
 
 void SketchSolver_ConstraintMultiTranslation::getAttributes(
     EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint,
@@ -63,3 +66,66 @@ const std::string& SketchSolver_ConstraintMultiTranslation::nameNbObjects()
 {
   return SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID();
 }
+
+void SketchSolver_ConstraintMultiTranslation::updateLocal()
+{
+  DataPtr aData = myBaseConstraint->data();
+  AttributePoint2DPtr aStartPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData,
+                                      SketchPlugin_MultiTranslation::START_POINT_ID());
+  AttributePoint2DPtr anEndPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData,
+                                      SketchPlugin_MultiTranslation::END_POINT_ID());
+  AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiTranslation::VALUE_TYPE());
+  bool aFullValue = aMethodTypeAttr->value() != "SingleValue";
+
+  bool aStartPointChanged = aStartPointAttribute != myStartPointAttribute;
+  bool anEndPointChanged = anEndPointAttribute != myEndPointAttribute;
+  bool isMethodChanged = aFullValue != myIsFullValue;
+
+  if (aStartPointChanged)
+    myStartPointAttribute = aStartPointAttribute;
+  if (aStartPointChanged)
+    myEndPointAttribute = anEndPointAttribute;
+  if (isMethodChanged)
+    myIsFullValue = aFullValue;
+
+  if (aStartPointChanged || anEndPointChanged || isMethodChanged) {
+    DataPtr aData = myBaseConstraint->data();
+    std::list<ConstraintWrapperPtr> aConstraints = myStorage->constraint(myBaseConstraint);
+    std::list<ConstraintWrapperPtr>::const_iterator anIt = aConstraints.begin(),
+                                                    aLast = aConstraints.end();
+    std::list<EntityWrapperPtr> anEntities;
+    for (; anIt != aLast; anIt++) {
+      ConstraintWrapperPtr aConstraint = *anIt;
+      aConstraint->setIsFullValue(myIsFullValue);
+      anEntities.clear();
+
+      const std::list<EntityWrapperPtr>& aConstraintEntities = aConstraint->entities();
+      std::list<EntityWrapperPtr>::const_iterator aSIt = aConstraintEntities.begin(),
+                                                  aSLast = aConstraintEntities.end();
+      EntityWrapperPtr aStartEntity = *aSIt++;
+      if (aStartPointChanged) {
+        AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID());
+        myStorage->update(aStartPointAttr);
+        aStartEntity = myStorage->entity(aStartPointAttr);
+      }
+      anEntities.push_back(aStartEntity);
+
+      EntityWrapperPtr anEndEntity = *aSIt++;
+      if (anEndPointChanged) {
+        AttributePtr anEndPointAttr = aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID());
+        myStorage->update(anEndPointAttr);
+        anEndEntity = myStorage->entity(anEndPointAttr);
+      }
+      anEntities.push_back(anEndEntity);
+
+      for (; aSIt != aSLast; ++aSIt)
+        anEntities.push_back(*aSIt);
+
+      aConstraint->setEntities(anEntities);
+    }
+    myStorage->addConstraint(myBaseConstraint, aConstraints);
+
+    myAdjusted = false;
+  }
+}
+
index 0e0c2faf1697375a72740fea634225a7c1fa48a1..a0f6ca525e8b89d153c3ea1c9caafe7230c85b22 100644 (file)
@@ -10,6 +10,8 @@
 #include "SketchSolver.h"
 #include <SketchSolver_ConstraintMulti.h>
 
+#include "GeomDataAPI_Point2D.h"
+
 /** \class   SketchSolver_ConstraintMultiTranslation
  *  \ingroup Plugins
  *  \brief   Convert translated features to the list of SolveSpace constraints
@@ -34,12 +36,16 @@ protected:
                      std::list< std::list<EntityWrapperPtr> >& theEntities);
 
   /// \brief Update parameters (called from base class)
-  virtual void updateLocal()
-  {}
+  virtual void updateLocal();
 
 private:
   /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature
   virtual const std::string& nameNbObjects();
+
+private:
+  AttributePoint2DPtr myStartPointAttribute;
+  AttributePoint2DPtr myEndPointAttribute;
+  bool                myIsFullValue;
 };
 
 #endif
index a0dd5261b547bd563a3ef96237e9b75c19715148..813e8dede94d5ff0638122d9327b17c35f2b7a75 100644 (file)
@@ -80,6 +80,13 @@ public:
   const double& value() const
   { return myValue; }
 
+  /// \brief Store a boolean flag for full value using
+  void setIsFullValue(const bool& theFullValue)
+  { myIsFullValue = theFullValue; }
+  /// \brief Return a flag of a full value using
+  const bool& isFullValue() const
+  { return myIsFullValue; }
+
   /// \brief Verify the feature is used in the constraint
   virtual bool isUsed(FeaturePtr theFeature) const = 0;
   /// \brief Verify the attribute is used in the constraint
@@ -96,6 +103,7 @@ protected:
   ConstraintPtr               myBaseConstraint;
   std::list<EntityWrapperPtr> myConstrained;
   double                      myValue;
+  bool                        myIsFullValue;
 };
 
 typedef std::shared_ptr<SketchSolver_IConstraintWrapper> ConstraintWrapperPtr;
index 34101a99145a96cf43b62a31764305f468db371a..2c47352adbda2c366a0c4e4702c0573d42ba1a62 100644 (file)
@@ -837,6 +837,13 @@ void adjustMultiTranslation(ConstraintWrapperPtr theConstraint)
   std::shared_ptr<GeomAPI_Pnt2d> aEndPnt = aBuilder->point(*aSIt++);
   std::shared_ptr<GeomAPI_XY> aDelta = aEndPnt->xy()->decreased(aStartPnt->xy());
 
+  bool isFullValue = theConstraint->isFullValue();
+  int aNbObjects = aSubs.size()-3;
+  if (isFullValue && aNbObjects > 0) {
+    aDelta->setX(aDelta->x()/aNbObjects);
+    aDelta->setY(aDelta->y()/aNbObjects);
+  }
+
   std::list<EntityWrapperPtr>::const_iterator aPrevIt = aSIt++;
   for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt)
     translate(*aPrevIt, *aSIt, aDelta);