]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom.git into Dev_0.6
authorsbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 18:55:00 +0000 (21:55 +0300)
committersbh <sergey.belash@opencascade.com>
Thu, 27 Nov 2014 18:55:00 +0000 (21:55 +0300)
29 files changed:
build_Salome740_deb.bat [deleted file]
build_Salome740_rel.bat [deleted file]
build_Salome_deb.bat [new file with mode: 0644]
build_Salome_rel.bat [new file with mode: 0644]
src/Model/Model_Data.cpp
src/ModelAPI/ModelAPI_Attribute.h
src/ModelAPI/ModelAPI_Object.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetShapeSelector.cpp [new file with mode: 0644]
src/PartSet/PartSet_WidgetShapeSelector.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Circle.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.h
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.h
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_PropertyPanel.cpp

diff --git a/build_Salome740_deb.bat b/build_Salome740_deb.bat
deleted file mode 100644 (file)
index 77a58f1..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-@ECHO OFF
-
-REM Find absolute path to ROOT_DIR 
-@SET PARENT_DIR=%~dp0..
-@SET ROOT_DIR=
-pushd %PARENT_DIR%
-@SET ROOT_DIR=%CD%
-popd
-
-@SET SRC_DIR=%ROOT_DIR%\sources
-@SET OCC_LIB_PREFIX=d
-
-call %SRC_DIR%\env_Salome.bat d
-mkdir %ROOT_DIR%\build
-cd %ROOT_DIR%\build
-
-cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
-
-start "" %MSVC_EXE% NewGEOM.sln
diff --git a/build_Salome740_rel.bat b/build_Salome740_rel.bat
deleted file mode 100644 (file)
index 26fbe15..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-@ECHO OFF
-
-REM Find absolute path to ROOT_DIR 
-@SET PARENT_DIR=%~dp0..
-@SET ROOT_DIR=
-pushd %PARENT_DIR%
-@SET ROOT_DIR=%CD%
-popd
-
-@SET SRC_DIR=%ROOT_DIR%\sources
-
-call %SRC_DIR%\env_Salome.bat
-mkdir %ROOT_DIR%\build
-cd %ROOT_DIR%\build
-
-cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
-
-start "" %MSVC_EXE% NewGEOM.sln
diff --git a/build_Salome_deb.bat b/build_Salome_deb.bat
new file mode 100644 (file)
index 0000000..77a58f1
--- /dev/null
@@ -0,0 +1,19 @@
+@ECHO OFF
+
+REM Find absolute path to ROOT_DIR 
+@SET PARENT_DIR=%~dp0..
+@SET ROOT_DIR=
+pushd %PARENT_DIR%
+@SET ROOT_DIR=%CD%
+popd
+
+@SET SRC_DIR=%ROOT_DIR%\sources
+@SET OCC_LIB_PREFIX=d
+
+call %SRC_DIR%\env_Salome.bat d
+mkdir %ROOT_DIR%\build
+cd %ROOT_DIR%\build
+
+cmake %SRC_DIR% -G "Visual Studio 10" -DPYTHON_EXECUTABLE=%PYTHONHOME%\python_d.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
+
+start "" %MSVC_EXE% NewGEOM.sln
diff --git a/build_Salome_rel.bat b/build_Salome_rel.bat
new file mode 100644 (file)
index 0000000..26fbe15
--- /dev/null
@@ -0,0 +1,18 @@
+@ECHO OFF
+
+REM Find absolute path to ROOT_DIR 
+@SET PARENT_DIR=%~dp0..
+@SET ROOT_DIR=
+pushd %PARENT_DIR%
+@SET ROOT_DIR=%CD%
+popd
+
+@SET SRC_DIR=%ROOT_DIR%\sources
+
+call %SRC_DIR%\env_Salome.bat
+mkdir %ROOT_DIR%\build
+cd %ROOT_DIR%\build
+
+cmake %SRC_DIR% -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=%ROOT_DIR%\install
+
+start "" %MSVC_EXE% NewGEOM.sln
index 5dcc138deeecbf1d46821c83b5e93fe7173cd6ce..0ae7a75aa3f3caf3e507ac2a8b57d2e725593744 100644 (file)
@@ -100,6 +100,7 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
   if (anAttr) {
     myAttrs[theID] = std::shared_ptr<ModelAPI_Attribute>(anAttr);
     anAttr->setObject(myObject);
+    anAttr->setID(theID);
   } else {
     Events_Error::send("Can not create unknown type of attribute " + theAttrType);
   }
@@ -195,7 +196,7 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
     static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
     ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
     if (myObject) {
-      myObject->attributeChanged();
+      myObject->attributeChanged(theAttr->id());
     }
   }
 }
index 27d65eb9b69eb8bc96b6ac5da4b680a5fb55acad..041e27b7cf5d7632493843cf917acb1f4c3230e2 100644 (file)
@@ -19,11 +19,12 @@ class ModelAPI_Attribute
 {
   ///< needed here to emit signal that feature changed on change of the attribute
   std::shared_ptr<ModelAPI_Object> myObject;
+  std::string myID; ///< identifier of this attribute in Data class
  protected:
   // accessible from the attributes
-  bool myIsInitialized;
-  bool myIsArgument;
-  bool myIsImmutable;
+  bool myIsInitialized; ///< is some value assigned to this attribute
+  bool myIsArgument;    ///< is this attribute used as an argument for execution
+  bool myIsImmutable;   ///< is this attribute can be changed programmatically (e.g. by constraint)
 
  public:
 
@@ -88,6 +89,12 @@ class ModelAPI_Attribute
     return myIsImmutable;
   }
 
+  /// ID of the attribute in Data
+  MODELAPI_EXPORT const std::string& id() const
+  {
+    return myID;
+  }
+
  protected:
   /// Objects are created for features automatically
   ModelAPI_Attribute()
@@ -97,6 +104,13 @@ class ModelAPI_Attribute
     myIsImmutable = false;
   }
 
+  /// Sets the ID of the attribute in Data (called from Data)
+  MODELAPI_EXPORT void setID(const std::string theID)
+  {
+    myID = theID;
+  }
+
+  friend class Model_Data;
 };
 
 //! Pointer on attribute object
index be488054077184cc2dc006ff80bd358387f635ce..3c8e6a6e8dfba3a5c6d450068895184dea638ec5 100644 (file)
@@ -55,7 +55,8 @@ class ModelAPI_Object
   virtual std::string groupName() = 0;
 
   /// Called on change of any argument-attribute of this object
-  MODELAPI_EXPORT virtual void attributeChanged() 
+  /// \param theID identifier of changed attribute
+  MODELAPI_EXPORT virtual void attributeChanged(const std::string& theID) 
   {}
 
   /// To use virtuality for destructors
index e7899b5d27e93ccccf75a9ebbf688ac750a1f908..211363d1661920c52520516f3498ec36407b4075 100644 (file)
@@ -133,9 +133,9 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const
     ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(mySelectedObject);
     if (aBody) {
       AttributePtr aAttr = aData->attribute(attributeID());
-      std::shared_ptr<ModelAPI_AttributeSelection> aSelectAttr = 
-        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
 
+      AttributeSelectionPtr aSelectAttr = 
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aAttr);
       if (aSelectAttr)
         aSelectAttr->setValue(aBody, myShape);
       updateObject(myFeature);
@@ -171,7 +171,7 @@ bool ModuleBase_WidgetShapeSelector::restoreValue()
   DataPtr aData = myFeature->data();
   bool isBlocked = this->blockSignals(true);
   if (myUseSubShapes) {
-    std::shared_ptr<ModelAPI_AttributeSelection> aSelect = aData->selection(attributeID());
+    AttributeSelectionPtr aSelect = aData->selection(attributeID());
     if (aSelect) {
       mySelectedObject = aSelect->context();
       myShape = aSelect->value();
index d0b04a6c63def6480f810b8aa412860eddc6d109..4cf0a4d2ed6ea6c70fe65c49a879befdf77e78cf 100644 (file)
@@ -35,7 +35,6 @@ Q_OBJECT
   virtual ~ModuleBase_WidgetShapeSelector();
 
   /// Saves the internal parameters to the given feature
-  /// \param theObject a model feature to be changed
   virtual bool storeValue() const;
 
   virtual bool restoreValue();
@@ -98,7 +97,7 @@ Q_OBJECT
   void setObject(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape = std::shared_ptr<GeomAPI_Shape>());
 
   //----------- Class members -------------
- private:
+ protected:
   QWidget* myContainer;
   QLabel* myLabel;
   QLineEdit* myTextLine;
index bdfcb5360a22edb668cc15777328d77659ec8ad7..a6c9c34e800b17fd35ffab39650ed045e2e8dfc2 100644 (file)
@@ -6,36 +6,24 @@ SET(PROJECT_HEADERS
        PartSet.h
        PartSet_Constants.h
        PartSet_EditLine.h
-#      PartSet_Listener.h
        PartSet_Module.h
-#      PartSet_OperationFeatureCreate.h
-#      PartSet_OperationFeatureEdit.h
-#      PartSet_OperationSketchBase.h
-#      PartSet_OperationSketch.h
-#      PartSet_OperationFeatureBase.h
        PartSet_Tools.h
        PartSet_WidgetSketchLabel.h
        PartSet_Validators.h
        PartSet_WidgetPoint2d.h
        PartSet_WidgetPoint2dDistance.h
-#      PartSet_Operation.h
+       PartSet_WidgetShapeSelector.h
 )
 
 SET(PROJECT_SOURCES
        PartSet_EditLine.cpp
-#      PartSet_Listener.cpp
        PartSet_Module.cpp
-#      PartSet_OperationFeatureCreate.cpp
-#      PartSet_OperationFeatureEdit.cpp
-#      PartSet_OperationSketchBase.cpp
-#      PartSet_OperationSketch.cpp
-#      PartSet_OperationFeatureBase.cpp
        PartSet_Tools.cpp
        PartSet_WidgetSketchLabel.cpp
        PartSet_Validators.cpp
        PartSet_WidgetPoint2d.cpp
        PartSet_WidgetPoint2dDistance.cpp
-#      PartSet_Operation.cpp
+       PartSet_WidgetShapeSelector.cpp
 )
 
 SET(PROJECT_RESOURCES 
index 7204c0e12b084f9d82b6f6b804bebe99a4c0b861..e115736c35b88993ef33b63eb81f03514f86b102 100644 (file)
@@ -9,7 +9,7 @@
 #include "PartSet_Tools.h"
 #include "PartSet_WidgetPoint2D.h"
 #include "PartSet_WidgetPoint2dDistance.h"
-//#include "PartSet_Operation.h"
+#include "PartSet_WidgetShapeSelector.h"
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_IViewer.h>
 #include <SketchPlugin_Point.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
 
 //#include <Config_PointerMessage.h>
 //#include <Config_ModuleReader.h>
@@ -399,11 +405,16 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t
 QStringList PartSet_Module::sketchOperationIdList() const
 {
   QStringList aIds;
-  aIds << SketchPlugin_Sketch::ID().c_str();
   aIds << SketchPlugin_Line::ID().c_str();
   aIds << SketchPlugin_Point::ID().c_str();
   aIds << SketchPlugin_Arc::ID().c_str();
   aIds << SketchPlugin_Circle::ID().c_str();
+  aIds << SketchPlugin_ConstraintLength::ID().c_str();
+  aIds << SketchPlugin_ConstraintDistance::ID().c_str();
+  aIds << SketchPlugin_ConstraintRigid::ID().c_str();
+  aIds << SketchPlugin_ConstraintRadius::ID().c_str();
+  aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
+  aIds << SketchPlugin_ConstraintParallel::ID().c_str();
   return aIds;
 }
 
@@ -858,6 +869,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
     aWgt->setWorkshop(aWorkshop);
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
+
   } else if (theType == "sketch-2dpoint_selector") {
     PartSet_WidgetPoint2D* aWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId);
     aWgt->setWorkshop(aWorkshop);
@@ -868,6 +880,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
 
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
+
   } if (theType == "point2ddistance") {
     PartSet_WidgetPoint2dDistance* aWgt = new PartSet_WidgetPoint2dDistance(theParent, theWidgetApi, theParentId);
     aWgt->setWorkshop(aWorkshop);
@@ -875,6 +888,15 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
 
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
+
+  } if (theType == "sketch_shape_selector") {
+    PartSet_WidgetShapeSelector* aWgt = 
+      new PartSet_WidgetShapeSelector(theParent, workshop(), theWidgetApi, theParentId);
+    aWgt->setSketcher(myCurrentSketch);
+
+    theModelWidgets.append(aWgt);
+    return aWgt->getControl();
+
   }else
     return 0;
 }
index dbb12d393902a87b589d170ecafbc5554a86ccf3..fdc4e25c8ffe186fec15a8e89b8f67eab9f1df53 100644 (file)
@@ -126,12 +126,8 @@ Handle(V3d_View) theView,
   theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z();
 }
 
-void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
-                                gp_Pnt& thePoint)
+std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr theSketch)
 {
-  if (!theSketch)
-    return;
-
   std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
 
   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
@@ -141,11 +137,10 @@ void PartSet_Tools::convertTo3D(const double theX, const double theY, FeaturePtr
   std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
 
-  std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
-      ->added(aY->dir()->xyz()->multiplied(theY));
+  std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
+    std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
 
-  std::shared_ptr<GeomAPI_Pnt> aPoint = std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
-  thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z());
+  return aPnt2d->to3D(aC->pnt(), aX->dir(), aY->dir());
 }
 
 ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
@@ -535,3 +530,39 @@ bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePt
 
   return aHasVertex;
 }
+
+AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, 
+                                                   const TopoDS_Shape theShape, 
+                                                   FeaturePtr theSketch)
+{
+
+  AttributePtr anAttribute;
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
+  if (aFeature) {
+    if (theShape.ShapeType() == TopAbs_VERTEX) {
+      const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape);
+      if (!aVertex.IsNull())  {
+        gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+        std::shared_ptr<GeomAPI_Pnt> aValue = std::shared_ptr<GeomAPI_Pnt>(
+            new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
+
+        // find the given point in the feature attributes
+        std::list<AttributePtr> anAttiributes = 
+          aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+        std::list<AttributePtr>::const_iterator anIt = anAttiributes.begin(), 
+                                                aLast = anAttiributes.end();
+        for (; anIt != aLast && !anAttribute; anIt++) {
+          std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+
+          std::shared_ptr<GeomAPI_Pnt> aPnt = convertTo3D(aCurPoint->x(), aCurPoint->y(), theSketch);
+          if (aPnt && (aPnt->distance(aValue) < Precision::Confusion())) {
+            anAttribute = aCurPoint;
+            break;
+          }
+        }
+      }
+    }
+  }
+  return anAttribute;
+}
index 53c98a47b33b5b0d9d7dedf2f6b4affa7e7355c1..522f0363d1a1a268522bf07aa1794f67c0adefa3 100644 (file)
 #include <QList>
 
 #include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Attribute.h>
+
+#include <TopoDS_Shape.hxx>
 
 #include <memory>
 
@@ -52,8 +56,7 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theY the Y coordinate
   /// \param theSketch the sketch feature
   /// \param thePoint the 3D point in the viewer
-  static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
-                          gp_Pnt& thePoint);
+  static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
 
   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
   /// if it exists, the first object is returned. Secondly, there is an iteration on
@@ -161,6 +164,16 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theY the output vertical coordinate of the point
   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
                              Handle_V3d_View theView, double& theX, double& theY);
+
+
+  /**
+  * Find attribute of object which corresponds to the given shape
+  * \param theObj - an object
+  * \param theShape - a Shape
+  * \param theSketch - a Sketch to get a plane of converting to 2d
+  */
+  static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
+
 protected:
   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
   /// if it exists, the first object is returned. Secondly, there is an iteration on
diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp
new file mode 100644 (file)
index 0000000..6036af1
--- /dev/null
@@ -0,0 +1,38 @@
+// File:        PartSet_WidgetShapeSelector.cpp
+// Created:     27 Nov 2014
+// Author:      Vitaly Smetannikov
+
+#include "PartSet_WidgetShapeSelector.h"
+
+#include <ModelAPI_AttributeRefAttr.h>
+#include <PartSet_Tools.h>
+
+
+bool PartSet_WidgetShapeSelector::storeValue() const
+{
+  if (!mySelectedObject)
+    return false;
+
+  FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
+  if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
+    return false;
+
+  DataPtr aData = myFeature->data();
+  if (myUseSubShapes && myShape) {
+    AttributePtr aAttr = aData->attribute(attributeID());
+    AttributeRefAttrPtr aRefAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+    if (aRefAttr) {
+      TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
+      AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
+      if (mySelectedObject)
+        aRefAttr->setObject(mySelectedObject);
+      if (aPntAttr)
+        aRefAttr->setAttr(aPntAttr);
+
+      updateObject(myFeature);
+      return true;
+    }
+  }
+  return ModuleBase_WidgetShapeSelector::storeValue();
+}
diff --git a/src/PartSet/PartSet_WidgetShapeSelector.h b/src/PartSet/PartSet_WidgetShapeSelector.h
new file mode 100644 (file)
index 0000000..a216830
--- /dev/null
@@ -0,0 +1,35 @@
+// File:        PartSet_WidgetShapeSelector.h
+// Created:     27 Nov 2014
+// Author:      Vitaly Smetannikov
+
+
+#ifndef PartSet_WidgetShapeSelector_H
+#define PartSet_WidgetShapeSelector_H
+
+#include "PartSet.h"
+
+#include <ModuleBase_WidgetShapeSelector.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+class PARTSET_EXPORT PartSet_WidgetShapeSelector: public ModuleBase_WidgetShapeSelector
+{
+Q_OBJECT
+ public:
+  PartSet_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+    const Config_WidgetAPI* theData, const std::string& theParentId)
+    : ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData, theParentId) {}
+
+  virtual ~PartSet_WidgetShapeSelector() {}
+
+  /// Saves the internal parameters to the given feature
+  virtual bool storeValue() const;
+
+  void setSketcher(CompositeFeaturePtr theSketch) { mySketch = theSketch; }
+  CompositeFeaturePtr sketch() const { return mySketch; }
+
+private:
+  CompositeFeaturePtr mySketch;
+};
+
+#endif
\ No newline at end of file
index 209f9744a7310e9483a080a96033975dd4f91599..eeb77874dd974b2a4b70e63c7502f264edd26f75 100644 (file)
@@ -100,18 +100,17 @@ bool SketchPlugin_Circle::isFixed() {
   return data()->selection(EXTERNAL_ID())->context();
 }
 
-void SketchPlugin_Circle::attributeChanged() {
-  static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change
-  std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
-  // update arguments due to the selection value
-  if (aSelection && !aSelection->isNull() && aSelection->isEdge() && !myIsUpdated) {
-    myIsUpdated = true;
-    std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
-    std::shared_ptr<GeomAPI_Circ> aCirc = anEdge->circle();
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
-    aCenterAttr->setValue(sketch()->to2D(aCirc->center()));
-    real(RADIUS_ID())->setValue(aCirc->radius());
-    myIsUpdated = false;
+void SketchPlugin_Circle::attributeChanged(const std::string& theID) {
+  if (theID == EXTERNAL_ID()) {
+    std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
+    // update arguments due to the selection value
+    if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
+      std::shared_ptr<GeomAPI_Circ> aCirc = anEdge->circle();
+      std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_ID()));
+      aCenterAttr->setValue(sketch()->to2D(aCirc->center()));
+      real(RADIUS_ID())->setValue(aCirc->radius());
+    }
   }
 }
index 8ceef34ebce1a521f54428ffa9a8a9e1b0c68965..08263db8c587c23797ff5866843a562d8e2bc4cc 100644 (file)
@@ -77,7 +77,7 @@ class SketchPlugin_Circle : public SketchPlugin_Feature  //, public GeomAPI_IPre
   virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
 
   /// Called on change of any argument-attribute of this object
-  SKETCHPLUGIN_EXPORT virtual void attributeChanged();
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
   /// Use plugin manager for features creation
   SketchPlugin_Circle();
index 97d41154c71e4fca2fdf1736c200605a28ed4b11..092d3c74cfedc4cfdcc5714e9eac186edc6cfd0c 100644 (file)
@@ -101,18 +101,12 @@ AISObjectPtr SketchPlugin_ConstraintDistance::getAISObject(AISObjectPtr thePrevi
   // value calculation
   std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
       ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
-  // TODO: has to be calculated on definition of reference object
-  double aValue;
+  double aValue = 0;
   // Issue #196: checking the positivity of the distance constraint
   // there is a validator for a distance constraint, that the value should be positive
   // in case if an invalid value is set, the current distance value is shown
   if (aValueAttr->isInitialized())
     aValue = aValueAttr->value();
-  else {
-    aValue = calculateCurrentDistance();
-    aValueAttr->setValue(aValue);
-  }
-  // End TODO
 
   AISObjectPtr anAIS = thePrevious;
   if (!anAIS)
@@ -168,6 +162,20 @@ double SketchPlugin_ConstraintDistance::calculateCurrentDistance() const
   return aDistance;
 }
 
+void SketchPlugin_ConstraintDistance::attributeChanged(const std::string& theID) {
+  if (theID == SketchPlugin_Constraint::ENTITY_A() || 
+      theID == SketchPlugin_Constraint::ENTITY_B()) 
+  {
+    std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+        ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+    if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+      double aDistance = calculateCurrentDistance();
+      if (aDistance > 0) { // set as value the length of updated references
+        aValueAttr->setValue(aDistance);
+      }
+    }
+  }
+}
 
 //*************************************************************************************
 std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
index 8ac80c3139df4e41830ff70033cc6095d987cb24..ef58b245317231c9075156e2550f2d52a66353a6 100644 (file)
@@ -56,6 +56,10 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// Returns the current distance between the feature attributes
   double calculateCurrentDistance() const;
 
index 5799a3a1284fd0c0cf7d12b6cd2e37341ccb0436..b5431fddf72378575778a29e232622d69b17ac2f 100644 (file)
@@ -51,32 +51,41 @@ void SketchPlugin_ConstraintLength::execute()
   }
 }
 
-AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePrevious)
+bool SketchPlugin_ConstraintLength::getPoints(
+  std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
+  std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
+  std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint)
 {
   if (!sketch())
-    return thePrevious;
-
+    return false;
   std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
-
   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
       ModelAPI_AttributeRefAttr>(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
   if (!anAttr)
-    return thePrevious;
+    return false;
   FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
   if (!aFeature || aFeature->getKind() != SketchPlugin_Line::ID())
-    return thePrevious;
-
-  std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
-      GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-
+    return false;
   DataPtr aData = aFeature->data();
-  std::shared_ptr<GeomDataAPI_Point2D> aStartPoint = std::dynamic_pointer_cast<
+  theStartPoint = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::START_ID()));
-  std::shared_ptr<GeomDataAPI_Point2D> anEndPoint = std::dynamic_pointer_cast<
+  theEndPoint = std::dynamic_pointer_cast<
       GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
+  thePoint1 = sketch()->to3D(theStartPoint->x(), theStartPoint->y());
+  thePoint2 = sketch()->to3D(theEndPoint->x(), theEndPoint->y());
+  return true;
+}
 
-  std::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aStartPoint->x(), aStartPoint->y());
-  std::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(anEndPoint->x(), anEndPoint->y());
+AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePrevious)
+{
+  std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
+  std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
+  if (!getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint))
+    return thePrevious; // not possible to show length because points are not defined
+
+  std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
   std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = std::shared_ptr<GeomAPI_Pnt>();
   if (aFlyOutAttr->isInitialized()) {
     aFlyoutPnt = sketch()->to3D(aFlyOutAttr->x(), aFlyOutAttr->y());
@@ -106,7 +115,8 @@ AISObjectPtr SketchPlugin_ConstraintLength::getAISObject(AISObjectPtr thePreviou
   anAIS->createDistance(aPoint1, aPoint2, aFlyoutPnt, aPlane, aValue);
 
   // Set color from preferences
-  std::vector<int> aRGB = Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR);
+  std::vector<int> aRGB = 
+    Config_PropManager::color("Visualization", "length_color", LENGTH_COLOR);
   anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
   return anAIS;
 }
@@ -122,3 +132,18 @@ void SketchPlugin_ConstraintLength::move(double theDeltaX, double theDeltaY)
   aPoint->move(theDeltaX, theDeltaY);
 }
 
+void SketchPlugin_ConstraintLength::attributeChanged(const std::string& theID) {
+  if (theID == SketchPlugin_Constraint::ENTITY_A()) 
+  {
+    std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+      ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+    if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+      std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
+      std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
+      if (getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) {
+        double aLength = aPoint1->distance(aPoint2);
+        aValueAttr->setValue(aLength);
+      }
+    }
+  }
+}
index 5f3ae9aae121173e9897dbf8268c5bd2f178c845..9cdd7e153fce2a676989ee9239862733e75583d5 100644 (file)
@@ -10,6 +10,8 @@
 #include <SketchPlugin_Sketch.h>
 #include <list>
 
+class GeomDataAPI_Point2D;
+
 #define LENGTH_COLOR "#ff00ff"
 
 /** \class SketchPlugin_ConstraintLength
@@ -50,8 +52,19 @@ class SketchPlugin_ConstraintLength : public SketchPlugin_ConstraintBase
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintLength();
+
+private:
+  // retrns the points-base of length, returns false if it is not possible
+  bool getPoints(
+    std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
+    std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
+    std::shared_ptr<GeomDataAPI_Point2D>& theEndPoint);
 };
 
 #endif
index 3aa6cba13a73865220469dfff36bb10f765833af..77fff3184de9e2816ae8f43c29db4f331fcca33c 100644 (file)
@@ -61,39 +61,58 @@ void SketchPlugin_ConstraintRadius::execute()
   }
 }
 
-AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePrevious)
+double SketchPlugin_ConstraintRadius::circleRadius(std::shared_ptr<ModelAPI_Feature>& theCirc)
 {
+  static const double kErrorResult = -1.;
   if (!sketch())
-    return thePrevious;
+    return kErrorResult;
 
   std::shared_ptr<ModelAPI_Data> aData = data();
   std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
       ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
   if (!anAttr)
-    return thePrevious;
-  FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr->object());
-  std::string aKind = aFeature ? aFeature->getKind() : "";
+    return kErrorResult;
+  theCirc = ModelAPI_Feature::feature(anAttr->object());
+  std::string aKind = theCirc ? theCirc->getKind() : "";
   if (aKind != SketchPlugin_Circle::ID() && aKind != SketchPlugin_Arc::ID())
-    return thePrevious;
+    return kErrorResult;
+
+  DataPtr aCircData = theCirc->data();
+  std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
+  if (aKind == SketchPlugin_Circle::ID()) {
+    AttributeDoublePtr aCircRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+        aCircData->attribute(SketchPlugin_Circle::RADIUS_ID()));
+    return aCircRadius->value();
+  } else {
+    aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+        aCircData->attribute(SketchPlugin_Arc::CENTER_ID()));
+    std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
+        GeomDataAPI_Point2D>(aCircData->attribute(SketchPlugin_Arc::START_ID()));
+    return aCenterAttr->pnt()->distance(aStartAttr->pnt());
+  }
+  return kErrorResult;
+}
+
+AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePrevious)
+{
+  std::shared_ptr<ModelAPI_Feature> aCyrcFeature;
+  double aRadius = circleRadius(aCyrcFeature);
+  if (aRadius < 0)
+    return thePrevious; // can not create a good presentation
 
   // Flyout point
   std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = std::dynamic_pointer_cast<
-      GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+      GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
   std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt;
   if (aFlyoutAttr->isInitialized()) {
     aFlyoutPnt = sketch()->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
   } 
 
   // Prepare a circle
-  std::shared_ptr<ModelAPI_Data> aCyrcData = aFeature->data();
   std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr;
-  double aRadius;
-  if (aKind == SketchPlugin_Circle::ID()) {
+  if (aCyrcFeature->getKind() == SketchPlugin_Circle::ID()) { // circle
     aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aCyrcData->attribute(SketchPlugin_Circle::CENTER_ID()));
-    AttributeDoublePtr aCircRadius = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
-        aCyrcData->attribute(SketchPlugin_Circle::RADIUS_ID()));
-    aRadius = aCircRadius->value();
+        aCyrcFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()));
     if (!aFlyoutPnt) {
       double aShift = aRadius * 1.1;
       std::shared_ptr<GeomAPI_Pnt2d> aPnt = aCenterAttr->pnt();
@@ -102,15 +121,12 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou
       aFlyoutAttr->setValue(aFPnt);
       aFlyoutPnt = sketch()->to3D(aFPnt->x(), aFPnt->y());
     }
-  } else if (aKind == SketchPlugin_Arc::ID()) {
+  } else { // arc
     aCenterAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aCyrcData->attribute(SketchPlugin_Arc::CENTER_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
-        GeomDataAPI_Point2D>(aCyrcData->attribute(SketchPlugin_Arc::START_ID()));
-    aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt());
+        aCyrcFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()));
     if (!aFlyoutPnt) {
       std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
-        GeomDataAPI_Point2D>(aCyrcData->attribute(SketchPlugin_Arc::START_ID()));      
+        GeomDataAPI_Point2D>(aCyrcFeature->data()->attribute(SketchPlugin_Arc::START_ID()));      
       aFlyoutAttr->setValue(aStartAttr->pnt());
       aFlyoutPnt = sketch()->to3D(aStartAttr->pnt()->x(), aStartAttr->pnt()->y());
     }
@@ -123,20 +139,14 @@ AISObjectPtr SketchPlugin_ConstraintRadius::getAISObject(AISObjectPtr thePreviou
   std::shared_ptr<GeomAPI_Circ> aCircle(new GeomAPI_Circ(aCenter, aNormal, aRadius));
 
   // Value
-  // TODO: has to be calculated on definition of reference object
   std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
-      ModelAPI_AttributeDouble>(aData->attribute(SketchPlugin_Constraint::VALUE()));
-  double aValue = aRadius;
+      ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
   if (aValueAttr->isInitialized())
-    aValue = aValueAttr->value();
-  else {
-    aValueAttr->setValue(aValue);
-  }
-  // End TODO
+    aRadius = aValueAttr->value();
   AISObjectPtr anAIS = thePrevious;
   if (!anAIS)
     anAIS = AISObjectPtr(new GeomAPI_AISObject);
-  anAIS->createRadius(aCircle, aFlyoutPnt, aValue);
+  anAIS->createRadius(aCircle, aFlyoutPnt, aRadius);
 
   // Set color from preferences
   std::vector<int> aRGB = Config_PropManager::color("Visualization", "radius_color", RADIUS_COLOR);
@@ -181,3 +191,17 @@ void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY)
 
   aFlyoutAttr->setValue(aFlyout->x(), aFlyout->y());
 }
+
+void SketchPlugin_ConstraintRadius::attributeChanged(const std::string& theID) {
+  if (theID == SketchPlugin_Constraint::ENTITY_A()) {
+    std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+        ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE()));
+    if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+      std::shared_ptr<ModelAPI_Feature> aCyrcFeature;
+      double aRadius = circleRadius(aCyrcFeature);
+      if (aRadius > 0) { // set as value the radius of updated reference to another circle
+        aValueAttr->setValue(aRadius);
+      }
+    }
+  }
+}
index 96e295e1b50f0227b3e4764061ff29d8fc441d29..7aa5ec6fbe10e2637e3d3c3a31b098ff1db03cbf 100644 (file)
@@ -49,8 +49,17 @@ class SketchPlugin_ConstraintRadius : public SketchPlugin_ConstraintBase
   /// \param theDeltaY the delta for Y coordinate is moved
   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintRadius();
+
+private:
+  /// Checks and gets the radius of referenced circle (or arc) otherwise returns -1.
+  /// \param theCircData the found referenced circle returned by this method
+  double circleRadius(std::shared_ptr<ModelAPI_Feature>& theCirc);
 };
 
 #endif
index 2cba979ce710164a078d324ea93bf8139ee9fe8f..83ee216593697877dd81eec97f23c76792bef900 100644 (file)
@@ -99,19 +99,18 @@ bool SketchPlugin_Line::isFixed() {
   return data()->selection(EXTERNAL_ID())->context();
 }
 
-void SketchPlugin_Line::attributeChanged() {
-  static bool myIsUpdated = false; // to avoid infinitive cycle on attrubtes change
-  std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
-   // update arguments due to the selection value
-  if (aSelection && !aSelection->isNull() && aSelection->isEdge() && !myIsUpdated) {
-    myIsUpdated = true;
-    std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
-    std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_ID()));
-    aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint()));
-    std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_ID()));
-    anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
-    myIsUpdated = false;
+void SketchPlugin_Line::attributeChanged(const std::string& theID) {
+  if (theID == EXTERNAL_ID()) {
+    std::shared_ptr<GeomAPI_Shape> aSelection = data()->selection(EXTERNAL_ID())->value();
+     // update arguments due to the selection value
+    if (aSelection && !aSelection->isNull() && aSelection->isEdge()) {
+      std::shared_ptr<GeomAPI_Edge> anEdge( new GeomAPI_Edge(aSelection));
+      std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_ID()));
+      aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint()));
+      std::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_ID()));
+      anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint()));
+    }
   }
 }
index a9e3e606cc6b931e6b9f097603dabaf873886d57..850d17e4a23e15b13ab3f7fd82cd1b9f69bf37c6 100644 (file)
@@ -68,7 +68,7 @@ class SketchPlugin_Line : public SketchPlugin_Feature
   virtual double distanceToPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
 
   /// Called on change of any argument-attribute of this object
-  SKETCHPLUGIN_EXPORT virtual void attributeChanged();
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 
   /// Use plugin manager for features creation
   SketchPlugin_Line();
index 213d38502c035f544756d33f6fddf48b0464019c..1793ff16a17b6bd8b248ff544ccfb401d16b0f91 100644 (file)
@@ -271,66 +271,46 @@ void SketchPlugin_Sketch::erase()
   ModelAPI_CompositeFeature::erase();
 }
 
-void SketchPlugin_Sketch::attributeChanged() {
-  static bool kIsUpdated = false; // to avoid infinitive cycle on attrubtes change
-  static bool kIsAttrChanged = false;
-  std::shared_ptr<GeomAPI_Shape> aSelection = 
-    data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
-  if (aSelection && !kIsUpdated) { // update arguments due to the selection value
-    kIsUpdated = true;
-    // update the sketch plane
-    std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
-    if (aPlane) {
-      double anA, aB, aC, aD;
-      aPlane->coefficients(anA, aB, aC, aD);
-
-      // calculate attributes of the sketch
-      std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
-      std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
-      std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
-      aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
-      std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
-      // X axis is preferable to be dirX on the sketch
-      static const double tol = 1.e-7;
-      bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
-      std::shared_ptr<GeomAPI_Dir> aTempDir(
-        isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
-      std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
-      std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
-
-      kIsAttrChanged = false; // track the attributes were really changed during the plane update
-      std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast
-        <GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-      anOrigin->setValue(anOrigPnt);
-      std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-        data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-      aNormal->setValue(aNormDir);
-      std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-        data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-      aDirX->setValue(aXDir);
-      std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-        data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
-      aDirY->setValue(aYDir);
-      std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
-
-      if (kIsAttrChanged) {
-        /* now it is in updater
-        // the plane was changed, so reexecute sub-elements to update shapes (located in new plane)
-        ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
-        list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
-        for(list<ObjectPtr>::iterator aSubIt = aSubs.begin(); aSubIt != aSubs.end(); aSubIt++) {
-          std::shared_ptr<SketchPlugin_Feature> aFeature = 
-            std::dynamic_pointer_cast<SketchPlugin_Feature>(*aSubIt);
-          if (aFeature && aFactory->validate(aFeature)) {
-            aFeature->execute();
-          }
-        }
-        */
-        kIsAttrChanged = false;
+void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
+  if (theID == SketchPlugin_Feature::EXTERNAL_ID()) {
+    std::shared_ptr<GeomAPI_Shape> aSelection = 
+      data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
+    if (aSelection) { // update arguments due to the selection value
+      // update the sketch plane
+      std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
+      if (aPlane) {
+        double anA, aB, aC, aD;
+        aPlane->coefficients(anA, aB, aC, aD);
+
+        // calculate attributes of the sketch
+        std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+        std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+        std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+        aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+        std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
+        // X axis is preferable to be dirX on the sketch
+        static const double tol = 1.e-7;
+        bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
+        std::shared_ptr<GeomAPI_Dir> aTempDir(
+          isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
+        std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
+        std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
+
+        // update position of the sketch
+        std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast
+          <GeomDataAPI_Point>(data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+        anOrigin->setValue(anOrigPnt);
+        std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+          data()->attribute(SketchPlugin_Sketch::NORM_ID()));
+        aNormal->setValue(aNormDir);
+        std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+          data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
+        aDirX->setValue(aXDir);
+        std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+          data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+        aDirY->setValue(aYDir);
+        std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
       }
     }
-    kIsUpdated = false;
-  } else if (kIsUpdated) { // other attributes are updated during the selection comupation
-    kIsAttrChanged = true;
   }
 }
index 66795f7bc266365599daf807136d7174cd956f66..0b4abaa4480b662728be3c6f25b790cf8caa86ae 100644 (file)
@@ -135,7 +135,7 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I
   /// Returns the point projected into the sketch plane
   std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt);
 
-  SKETCHPLUGIN_EXPORT virtual void attributeChanged();
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
 protected:
   /// Creates a plane and append it to the list
   /// \param theX the X normal value
index d0881383bd2f24eb336e4d83936fc12b9e60821a..4395e92fcba66b05d159391b902c6dd1cfecd954 100644 (file)
 
       <feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object" icon=":icons/distance.png">
         <label title="Select objects for distance definition. Following objects can be accepted: point, line or arc end point, center of circle or arc."/>
-               <shape_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc." 
-                       shape_types="edge vertex"/>
-               <shape_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc." 
-                       shape_types="edge vertex"/>
+               <sketch_shape_selector id="ConstraintEntityA" label="First object" tooltip="Select point, line end point, line, center of circle or arc." 
+                       shape_types="edge vertex"  use_subshapes="true"/>
+               <sketch_shape_selector id="ConstraintEntityB" label="Last object" tooltip="Select point, line end point, line, center of circle or arc." 
+                       shape_types="edge vertex"  use_subshapes="true"/>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed" min="0">
           <validator id="GeomValidators_Positive"/>
index c5b1a50d7ad70b6e6133f8c7e1494166c43a296b..04655869a267485433239823aba809a68e8a63ac 100644 (file)
@@ -97,6 +97,7 @@ void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& t
     //if (aPointWidget)
     //  connect(aPointWidget, SIGNAL(storedPoint2D(ObjectPtr, const std::string&)), this,
     //          SIGNAL(storedPoint2D(ObjectPtr, const std::string&)))
+    //}
 
     if (!isEnableStretch) continue;
     foreach(QWidget* eachWidget, (*anIt)->getControls()) {