Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Tue, 17 Jun 2014 17:06:58 +0000 (21:06 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 17 Jun 2014 17:06:58 +0000 (21:06 +0400)
1. The cross product for a line to find the constraint direction relatively to the source line feature

14 files changed:
src/GeomAPI/GeomAPI_Lin2d.cpp
src/GeomAPI/GeomAPI_Lin2d.h
src/ModelAPI/ModelAPI_AttributeDouble.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/PartSet/PartSet_FeatureLengthPrs.cpp
src/PartSet/PartSet_FeatureLinePrs.cpp
src/PartSet/PartSet_FeatureLinePrs.h
src/PartSet/PartSet_OperationConstraint.cpp
src/PartSet/PartSet_OperationCreateConstraint.cpp
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_Presentation.cpp
src/PartSet/PartSet_Tools.cpp
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.cpp

index 8eb102ae56b235f99da82eb63b629de463085271..1299c75032db1b12fb1a4062f2090f49412ca737 100644 (file)
@@ -60,3 +60,11 @@ const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::project(const boost::share
   return boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aResult.X(), aResult.Y()));
 }
 
+double GeomAPI_Lin2d::crossed(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
+{
+  const gp_XY& aDir = MY_LIN2D->Direction().XY();
+  const gp_XY& aLoc = MY_LIN2D->Location().XY();
+  const gp_XY& aPnt = thePoint->impl<gp_Pnt2d>().XY();
+
+  return aDir.Crossed(aPnt - aLoc);
+}
index 32f55d3ed79d08a8fe9e76f173405a83f953cd00..2344648ea230aeb51b2471e89522e75494b007df 100644 (file)
@@ -31,6 +31,8 @@ public:
   const boost::shared_ptr<GeomAPI_Pnt2d> intersect(const boost::shared_ptr<GeomAPI_Lin2d>& theLine) const;
   /// Project point on line
   const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
+  /// Computes the cross product of the line direction and a vector from the line start point to the point
+  double crossed(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
 };
 
 #endif
index 81bdb66904dc4702a0454ee3b4c356ad9088ca0e..8377573092c7d8012c63c3282fd4c14f5cf7d19e 100644 (file)
@@ -36,4 +36,7 @@ protected:
   {}
 };
 
+//! Pointer on double attribute
+typedef boost::shared_ptr<ModelAPI_AttributeDouble> AttributeDoublePtr;
+
 #endif
index 9c02822e8f0b42ba119f63f9fec865a0c8c6cd2c..b17b98f1174225e48e157020ae6beff95d4f617b 100644 (file)
@@ -89,7 +89,7 @@ ModuleBase_WidgetDoubleValue::~ModuleBase_WidgetDoubleValue()
 bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const
 {
   DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(attributeID());
+  AttributeDoublePtr aReal = aData->real(attributeID());
   if (aReal->value() != mySpinBox->value()) {
     aReal->setValue(mySpinBox->value());
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
@@ -100,7 +100,7 @@ bool ModuleBase_WidgetDoubleValue::storeValue(FeaturePtr theFeature) const
 bool ModuleBase_WidgetDoubleValue::restoreValue(FeaturePtr theFeature)
 {
   DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeDouble> aRef = aData->real(attributeID());
+  AttributeDoublePtr aRef = aData->real(attributeID());
 
   bool isBlocked = mySpinBox->blockSignals(true);
   mySpinBox->setValue(aRef->value());
index 944e7c51e562c71a3577d66e4af0dd63d4fa7d0a..c8390f99114ce525027f64fd77fe7cbef09306e2 100644 (file)
@@ -5,6 +5,8 @@
 #include <PartSet_FeatureLengthPrs.h>
 #include <PartSet_Tools.h>
 
+#include <PartSet_FeatureLinePrs.h>
+
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Line.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Lin2d.h>
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeDouble.h>
 
 #include <Precision.hxx>
 
@@ -44,15 +48,34 @@ PartSet_SelectionMode PartSet_FeatureLengthPrs::setPoint(double theX, double the
     }
     break;
     case SM_SecondPoint: {
-      /*boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-      boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
-                                                                  (aData->attribute(CIRCLE_ATTR_CENTER));
-      boost::shared_ptr<GeomAPI_Pnt2d> aCoordPoint(new GeomAPI_Pnt2d(theX, theY));
-      double aRadius = aCoordPoint->distance(aPoint->pnt());
-      PartSet_Tools::setFeatureValue(feature(), aRadius, CIRCLE_ATTR_RADIUS);
-
-      aMode = SM_DonePoint;*/
-   }
+      boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+      boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+              boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+      FeaturePtr aFeature;
+      if (anAttr) {
+        aFeature = anAttr->feature();
+        if (aFeature->getKind() != SKETCH_LINE_KIND) {
+          aFeature = FeaturePtr();
+        }
+      }
+      boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
+                                                             (new GeomAPI_Pnt2d(theX, theY));
+      boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(aFeature);
+      boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
+      double aDistance = aPoint->distance(aResult);
+
+      double aStartX, aStartY;
+      PartSet_FeatureLinePrs::getLinePoint(aFeature, LINE_ATTR_START, aStartX, aStartY);
+
+      if (aFeatureLin->crossed(aPoint) < 0)
+        aDistance = -aDistance;
+
+      AttributeDoublePtr aFlyoutAttr = 
+          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+      aFlyoutAttr->setValue(aDistance);
+
+      aMode = SM_DonePoint;
+    }
     break;
     default:
       break;
index ae85a3d88b730f0e81ae7150f4a4e552aab6395f..bc7e2d14433cc953f5594d6a0f3dfe1563527da6 100644 (file)
@@ -125,15 +125,13 @@ void PartSet_FeatureLinePrs::projectPointOnLine(FeaturePtr theFeature,
                                                 double& theX, double& theY)
 {
   if (theFeature && theFeature->getKind() == getKind()) {
-    double X0, X1, X2, X3;
-    double Y0, Y1, Y2, Y3;
-    getLinePoint(theFeature, LINE_ATTR_START, X2, Y2);
-    getLinePoint(theFeature, LINE_ATTR_END, X3, Y3);
+    double X0, X1;
+    double Y0, Y1;
 
     PartSet_Tools::convertTo2D(thePoint, sketch(), theView, X1, Y1);
     boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(X1, Y1));
-    boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
-                                                         (new GeomAPI_Lin2d(X2, Y2, X3, Y3));
+    boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = PartSet_FeatureLinePrs::createLin2d(theFeature);
+
     switch (theMode) {
       case SM_FirstPoint: {
         boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aPoint);
@@ -211,6 +209,21 @@ boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::findPoint(Feature
   return aPoint2D;
 }
 
+boost::shared_ptr<GeomAPI_Lin2d> PartSet_FeatureLinePrs::createLin2d(FeaturePtr theFeature)
+{
+  boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin;
+  if (!theFeature || theFeature->getKind() != PartSet_FeatureLinePrs::getKind())
+    return aFeatureLin;
+
+  double aStartX, aStartY, anEndX, anEndY;
+  getLinePoint(theFeature, LINE_ATTR_START, aStartX, aStartY);
+  getLinePoint(theFeature, LINE_ATTR_END, anEndX, anEndY);
+
+  aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
+                                        (new GeomAPI_Lin2d(aStartX, aStartY, anEndX, anEndY));
+  return aFeatureLin;
+}
+
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_FeatureLinePrs::featurePoint
                                                      (const PartSet_SelectionMode& theMode)
 {
index 08ccc3837adeabee3cf33bb39a3940a034243c88..0f6fb051fd323e99a009e42f01543b06e0038619 100644 (file)
@@ -13,6 +13,7 @@
 #include <gp_Pnt.hxx>
 
 class GeomDataAPI_Point2D;
+class GeomAPI_Lin2d;
 class Handle_V3d_View;
 
 /*!
@@ -80,6 +81,17 @@ public:
   virtual boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
                                                            double theY);
 
+  /// Creates a lin 2d object on a base of the line feature
+  /// \param theFeature the line feature
+  static boost::shared_ptr<GeomAPI_Lin2d> createLin2d(FeaturePtr theFeature);
+  /// \brief Get the line point 2d coordinates.
+  /// \param theFeature the line feature
+  /// \param theAttribute the start or end attribute of the line
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
+                           double& theX, double& theY);
+
 protected:
   /// Initializes current feature by the given
   /// \param theSourceFeature the feature, which attributes are used to initialize the current feature
@@ -88,14 +100,6 @@ protected:
   /// Returns the feature point in the selection mode position.
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
   virtual boost::shared_ptr<GeomDataAPI_Point2D> featurePoint(const PartSet_SelectionMode& theMode);
-
-  /// \brief Get the line point 2d coordinates.
-  /// \param theFeature the line feature
-  /// \param theAttribute the start or end attribute of the line
-  /// \param theX the horizontal coordinate
-  /// \param theY the vertical coordinate
-  static void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
-                           double& theX, double& theY);
 };
 
 #endif
index 3a96b309a914e48be00cf398f2d283e0a2a90d25..e810cf39092bd9b50c45b5409abdf7e603eaa24a 100644 (file)
@@ -162,7 +162,7 @@ void PartSet_OperationConstraint::setValue(const double theValue)
 {
   boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
 
-  boost::shared_ptr<ModelAPI_AttributeDouble> anAttr = 
+  AttributeDoublePtr anAttr = 
           boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
   anAttr->setValue(theValue);
 
index a648c82a00b40865be2d5eca3564b14d57302e68..78d0fe251cfc3b065f670937342f15024d11e65d 100644 (file)
@@ -53,8 +53,8 @@ PartSet_OperationCreateConstraint::~PartSet_OperationCreateConstraint()
 
 bool PartSet_OperationCreateConstraint::canProcessKind(const std::string& theId)
 {
-  return /*theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND ||
-         theId == SKETCH_ARC_KIND || */theId == SKETCH_CONSTRAINT_LENGTH_KIND;
+  // changed
+  return theId == SKETCH_CONSTRAINT_LENGTH_KIND;
 }
 
 bool PartSet_OperationCreateConstraint::canBeCommitted() const
@@ -79,7 +79,8 @@ void PartSet_OperationCreateConstraint::init(FeaturePtr theFeature,
                                        const std::list<XGUI_ViewerPrs>& /*theSelected*/,
                                        const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
-  if (!theFeature || theFeature->getKind() != SKETCH_LINE_KIND)
+  // changed
+  if (!theFeature/* || theFeature->getKind() != SKETCH_LINE_KIND*/)
     return;
   myInitFeature = theFeature;
 }
@@ -93,25 +94,45 @@ void PartSet_OperationCreateConstraint::mouseReleased(QMouseEvent* theEvent, Han
                                                 const std::list<XGUI_ViewerPrs>& theSelected,
                                                 const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
-  if (theSelected.empty()) {
-
-  }
-  else {
-    XGUI_ViewerPrs aPrs = theSelected.front();
-    FeaturePtr aFeature = aPrs.feature();
+  switch (myPointSelectionMode)
+  {
+    case SM_FirstPoint: {
+      if (!theSelected.empty()) {
+        XGUI_ViewerPrs aPrs = theSelected.front();
+        FeaturePtr aFeature = aPrs.feature();
+
+        myFeaturePrs->init(feature(), aFeature);
+        flushUpdated();
+        setPointSelectionMode(SM_SecondPoint);
+      }
+    }
+    break;
+    case SM_SecondPoint: {
+      double aX, anY;
+      gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
+      PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
 
-    myFeaturePrs->init(feature(), aFeature);
-    flushUpdated();
+      PartSet_SelectionMode aMode = myFeaturePrs->setPoint(aX, anY, myPointSelectionMode);
+      flushUpdated();
+      // show value edit dialog
+      //setPointSelectionMode(aMode);
+      commit();
+      restartOperation(feature()->getKind(), FeaturePtr());
+    }
+    break;
+    default:
+      break;
   }
 }
 
 void PartSet_OperationCreateConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
 {
+  // changed
   switch (myPointSelectionMode)
   {
-    case SM_FirstPoint:
+    //case SM_FirstPoint:
     case SM_SecondPoint:
-    case SM_ThirdPoint:
+    //case SM_ThirdPoint:
     {
       double aX, anY;
       gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
index 7966e9ed1f2d814a1d96fb96e41ca91190f6c9da..bc57e5068e87db6b041060bc5c06ab61f6364614 100644 (file)
@@ -194,7 +194,7 @@ bool PartSet_OperationSketch::hasSketchPlane() const
 
   if (feature()) {
     boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
-    boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+    AttributeDoublePtr anAttr;
     boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
       boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
     aHasPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
index 18fcce5f8cec21dac97e03d4666089dc137ff4d2..84dc7e3fe10ea98d613fe083a0757f738c5d122f 100644 (file)
@@ -122,6 +122,11 @@ Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength
   //Build dimension here
   gp_Pnt aP1 = aPoint1;
   gp_Pnt aP2 = aPoint2;
+  if (aFlyout < 0) {
+    aP1 = aPoint2;
+    aP2 = aPoint1;
+  }
+
 
   Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
   if (anAIS.IsNull())
@@ -148,6 +153,8 @@ Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength
     Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
     if (!aDimAIS.IsNull()) {
       aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
+      aDimAIS->SetFlyout(aFlyout);
+
       aDimAIS->Redisplay(Standard_True);
     }
   }
index 615f79a281f62e8e36e5947137acd59c3ed7101a..451971a16c145ef5e60f0f699aba57552b804388 100644 (file)
@@ -73,7 +73,7 @@ void PartSet_Tools::convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
   if (!theSketch)
     return;
 
-  boost::shared_ptr<ModelAPI_AttributeDouble> anAttr;
+  AttributeDoublePtr anAttr;
   boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
 
   boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
@@ -237,7 +237,7 @@ void PartSet_Tools::setFeatureValue(FeaturePtr theFeature, double theValue,
   if (!theFeature)
     return;
   boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeDouble> anAttribute =
+  AttributeDoublePtr anAttribute =
         boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(theAttribute));
   if (anAttribute)
     anAttribute->setValue(theValue);
index d58a58dd76f1de3b5617291bfc921f62f19e753c..eaa284d083b9fc28b61ceb1540f580987f685e30 100644 (file)
@@ -51,7 +51,7 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Circle::preview()
     if (aHasPlane) {
       boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
       // compute the circle radius
-      boost::shared_ptr<ModelAPI_AttributeDouble> aRadiusAttr = 
+      AttributeDoublePtr aRadiusAttr = 
         boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CIRCLE_ATTR_RADIUS));
       double aRadius = aRadiusAttr->value();
 
index 186e80505628cc859a2da9867c6558333338a0b2..6ee9f2e429438a2421ee5bd2d460f7466cce28d2 100644 (file)
@@ -162,7 +162,7 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
 
   // Create constraint parameters
   double aDistance = 0.0; // scalar value of the constraint
-  boost::shared_ptr<ModelAPI_AttributeDouble> aDistAttr =
+  AttributeDoublePtr aDistAttr =
     boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theConstraint->data()->attribute(CONSTRAINT_ATTR_VALUE));
   if (aDistAttr)
   {
@@ -288,7 +288,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity(
   }
 
   // Scalar value (used for the distance entities)
-  boost::shared_ptr<ModelAPI_AttributeDouble> aScalar = 
+  AttributeDoublePtr aScalar = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theEntity);
   if (aScalar)
   {
@@ -810,7 +810,7 @@ void SketchSolver_ConstraintGroup::updateAttribute(
   }
 
   // Scalar value
-  boost::shared_ptr<ModelAPI_AttributeDouble> aScalar = 
+  AttributeDoublePtr aScalar = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
   if (aScalar)
   {