]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
authornds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 15:37:52 +0000 (19:37 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 15:37:52 +0000 (19:37 +0400)
Length constraint.

src/ModuleBase/ModuleBase_WidgetEditor.cpp
src/PartSet/PartSet_ConstraintLengthPrs.cpp
src/PartSet/PartSet_ConstraintRadiusPrs.cpp
src/PartSet/PartSet_OperationFeatureCreate.cpp
src/SketchPlugin/SketchPlugin_Constraint.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.h
src/SketchPlugin/plugin-Sketch.xml

index f62eae3d3fbe4085328d8c643146d0e566c83850..afffeeae464fb206fd473b5472035b28815dda83 100644 (file)
@@ -31,15 +31,13 @@ ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent,
 
 ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor()
 {
-  //delete myEditor;
 }
 
 bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const
 {
   DataPtr aData = theFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
-  bool isOk;
-  if (isOk && aReal->value() != myValue) {
+  if (aReal->value() != myValue) {
     aReal->setValue(myValue);
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
   }
@@ -74,6 +72,7 @@ void ModuleBase_WidgetEditor::focusTo()
   if (aRes == QDialog::Accepted)
     myValue = aEditor->text().toDouble();
 
+  emit valuesChanged();
   emit focusOutWidget(this);
 }
 
index 4607b732b71ee40a33f58e2bbd637193204622fe..9e4140291c83a4985c8d553e82812d6ad5838a99 100644 (file)
@@ -97,9 +97,9 @@ PartSet_SelectionMode PartSet_ConstraintLengthPrs::setPoint(double theX, double
       if (!aFeatureLin->isRight(aPoint))
         aDistance = -aDistance;
 
-      AttributeDoublePtr aFlyoutAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-      aFlyoutAttr->setValue(aDistance);
+      //AttributeDoublePtr aFlyoutAttr = 
+      //    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+      //aFlyoutAttr->setValue(aDistance);
 
       aMode = SM_DonePoint;
     }
index 659eff3f8170c2e0b7c27f699d4c82de2b50a73c..92caca86b9651cca674116966c3693b1c29c2305 100644 (file)
@@ -90,7 +90,7 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double
       boost::shared_ptr<GeomAPI_Pnt2d> aPoint = boost::shared_ptr<GeomAPI_Pnt2d>
                                                              (new GeomAPI_Pnt2d(theX, theY));
 
-      PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT);
+      //PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT);
 
       //double aDistance = 40;
       //AttributeDoublePtr aFlyoutAttr = 
index a45a854191fea0e8216c70799919786d8029adfa..5da96ccb9dd0fc0538a045e30a2ecf39be67d3b3 100644 (file)
@@ -61,9 +61,9 @@ bool PartSet_OperationFeatureCreate::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_DISTANCE_KIND /*||
+         theId == SKETCH_CONSTRAINT_DISTANCE_KIND ||
          theId == SKETCH_CONSTRAINT_LENGTH_KIND ||
-         theId == SKETCH_CONSTRAINT_RADIUS_KIND ||
+         theId == SKETCH_CONSTRAINT_RADIUS_KIND /*||
          theId == SKETCH_CONSTRAINT_PARALLEL_KIND ||
          theId == SKETCH_CONSTRAINT_PERPENDICULAR_KIND*/;
 }
index 50abf8636921b4362d84dff745591afcd7fd793c..632243ba608557cc11ea325f61724794fde566ce 100644 (file)
@@ -32,8 +32,6 @@ const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection toler
 const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue");
 /// The 2D value parameter for the constraint
 const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
-/// The value parameter for the constraint
-const std::string CONSTRAINT_ATTR_FLYOUT_VALUE("ConstraintFlyoutValue");
 /// First entity for the constraint
 const std::string CONSTRAINT_ATTR_ENTITY_A("ConstraintEntityA");
 /// Second entity for the constraint
index 6e37f0cbe1094964f924c483b40a5a6007198842..ad8eda3a7ba3d617c8169a6f3edcb6a84ba8c6c3 100644 (file)
@@ -77,9 +77,8 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape(
   boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = 
     boost::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(),
                                                        aPoint_B->x(), aPoint_B->y()));
-  boost::shared_ptr<GeomAPI_Pnt2d> aResult = aFeatureLin->project(aFlyOutPnt);
-  double aDistance = aFlyOutPnt->distance(aResult);
-
+  boost::shared_ptr<GeomAPI_Pnt2d> aProjectedPoint = aFeatureLin->project(aFlyOutPnt);
+  double aDistance = aFlyOutPnt->distance(aProjectedPoint);
   if (!aFeatureLin->isRight(aFlyOutPnt))
     aDistance = -aDistance;
   double aFlyout = aDistance;
@@ -87,16 +86,11 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape(
   //Build dimension here
   boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y());
   boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y());
-  if (aFlyout < 0)
-    aPoint1.swap(aPoint2);
 
   // value calculation
   boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
   double aValue = aValueAttr->value();
-  if (aValue == 0) { // TODO! the default value
-    aValue = aPoint1->distance(aPoint2);
-  }
 
   Handle(AIS_InteractiveObject) anAIS = thePrevious;
   if (anAIS.IsNull())
index 6e48926c662b7f26eeedfd4cedab1b415ce5d7b6..7f54f794778dd8b8d7fc235a31e97d662ca396ae 100644 (file)
@@ -12,6 +12,9 @@
 
 #include <GeomDataAPI_Point2D.h>
 
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+
 #include <AIS_LengthDimension.hxx>
 #include <gp_Pnt.hxx>
 #include <gp_Pln.hxx>
@@ -23,13 +26,33 @@ SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength()
 void SketchPlugin_ConstraintLength::initAttributes()
 {
   data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
-  data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
+  //data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
   data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
 }
 
 void SketchPlugin_ConstraintLength::execute()
 {
+  if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() &&
+      !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) {
+
+    boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+      boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+    FeaturePtr aFeature = aRef->feature();
+    if (aFeature) {
+      // set length value
+      boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_START));
+      boost::shared_ptr<GeomDataAPI_Point2D> aPoint2 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_END));
+
+      double aLenght = aPoint1->pnt()->distance(aPoint2->pnt());
+
+      boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
+        boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
+      aValueAttr->setValue(aLenght);
+    }
+  }
 }
 
 Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape(
@@ -48,10 +71,29 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape(
   if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
     return thePrevious;
 
-  boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
-    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-  double aFlyout = aFlyoutAttr->value();
-
+  //boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
+  //  boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+  //double aFlyout = aFlyoutAttr->value();
+  // fly out calculation
+  boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_START));
+  boost::shared_ptr<GeomDataAPI_Point2D> anEndPoint =
+     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(LINE_ATTR_END));
+
+  boost::shared_ptr<GeomAPI_Lin2d> aFeatureLin = boost::shared_ptr<GeomAPI_Lin2d>
+                                             (new GeomAPI_Lin2d(aStartPoint->x(), aStartPoint->y(),
+                                                                anEndPoint->x(), anEndPoint->y()));
+  boost::shared_ptr<GeomAPI_Pnt2d> aProjectedPoint = aFeatureLin->project(aFlyOutPnt);
+  double aDistance = aFlyOutPnt->distance(aProjectedPoint);
+  if (!aFeatureLin->isRight(aFlyOutPnt))
+    aDistance = -aDistance;
+  double aFlyout = aDistance;
+
+  // value
   boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
   double aValue = aValueAttr->value();
@@ -68,8 +110,6 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape(
   //Build dimension here
   boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPointStart->x(), aPointStart->y());
   boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPointEnd->x(),   aPointEnd->y());
-  if (aFlyout < 0)
-    aPoint1.swap(aPoint2);
 
   Handle(AIS_InteractiveObject) anAIS = thePrevious;
   if (anAIS.IsNull())
index a57df918bd87de76a418d15b5c78b1b9613cfca2..8cdb822ae78104175a33a1aa66c1f2eb4662e29a 100644 (file)
@@ -27,13 +27,12 @@ void SketchPlugin_ConstraintRadius::initAttributes()
 {
   data()->addAttribute(CONSTRAINT_ATTR_VALUE,    ModelAPI_AttributeDouble::type());
   data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type());
-
-  data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type());
-  data()->addAttribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT, GeomDataAPI_Point2D::type());
+  data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type());
 }
 
 void SketchPlugin_ConstraintRadius::execute()
 {
+
 }
 
 Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
@@ -59,7 +58,7 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
 
   // an anchor point
   boost::shared_ptr<GeomDataAPI_Point2D> aAnchorAttr = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT));
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
   boost::shared_ptr<GeomAPI_Pnt2d> anAnchor2D = aAnchorAttr->pnt();
   boost::shared_ptr<GeomAPI_Pnt> anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y());
 
index 7af115ce9f14651a7a2af1849e87a835c1e523d4..4ff63b2e8858d6898fcbb287492b4b5f01a45fc0 100644 (file)
 /// Radius constraint kind
 const std::string SKETCH_CONSTRAINT_RADIUS_KIND("SketchConstraintRadius");
 
-/// Start 2D point of the line
-const std::string SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT("CirclePoint");
-
-
 /** \class SketchPlugin_ConstraintRadius
  *  \ingroup DataModel
  *  \brief Feature for creation of a new constraint which defines 
index 8cff21c494fe019dc8d8894c5632cbaf29f95dec..c4bbaab49988c4ce18ba31730355ea68b429227e 100644 (file)
@@ -38,7 +38,7 @@
       <feature id="SketchConstraintRadius" title="Radius of a circle or an arc" tooltip="Create constraint for the given radius of a circle or an arc">
         <label title="Select two points on a circle or an arc of circle on which to calculate radius" tooltip="Select two points on a circle or an arc of circle on which to calculate radius"/>
         <feature_selector id="ConstraintEntityA" keysequence="SketchPoint" internal="1"/>
-        <point_selector id="CirclePoint" internal="1"/>
+        <point_selector id="ConstraintFlyoutValuePnt" internal="1"/>
         <doublevalue_editor id="ConstraintValue"/>
       </feature>
       <feature id="SketchConstraintParallel" title="Parallelism of a lines" tooltip="Create constraint defining two parallel lines">