]> 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 16:03:25 +0000 (20:03 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 16:03:25 +0000 (20:03 +0400)
Length and distance constraint initalization of constraint value.

src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp

index ad8eda3a7ba3d617c8169a6f3edcb6a84ba8c6c3..e5480db6c3e22185cf63c80125dc1601528f2203 100644 (file)
@@ -45,13 +45,22 @@ void SketchPlugin_ConstraintDistance::execute()
 
   AttributeDoublePtr anAttr_Value =
       boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-  if (anAttr_A && anAttr_B && !anAttr_Value->isInitialized())
+  if (anAttr_A->isInitialized() && anAttr_B->isInitialized() && !anAttr_Value->isInitialized())
   {
     FeaturePtr aFeature_A = anAttr_A->feature();
     FeaturePtr aFeature_B = anAttr_B->feature();
-
-    double aValue = 40; // TODO
-    anAttr_Value->setValue(aValue);
+    if (aFeature_A && aFeature_A) {
+      // calculate the distance
+      boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                             (aFeature_A->data()->attribute(POINT_ATTR_COORD));
+      boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                             (aFeature_B->data()->attribute(POINT_ATTR_COORD));
+      if (aPoint_A && aPoint_B) {
+        anAttr_Value->setValue(aPoint_A->pnt()->distance(aPoint_B->pnt()));
+      }
+    }
   }
 }
 
@@ -72,16 +81,19 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape(
   // fly out calculation
   boost::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = 
     boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
-  boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
-
-  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> aProjectedPoint = aFeatureLin->project(aFlyOutPnt);
-  double aDistance = aFlyOutPnt->distance(aProjectedPoint);
-  if (!aFeatureLin->isRight(aFlyOutPnt))
-    aDistance = -aDistance;
-  double aFlyout = aDistance;
+  double aFlyout = 0;
+  if (aFlyOutAttr->isInitialized()) {
+    boost::shared_ptr<GeomAPI_Pnt2d> aFlyOutPnt = aFlyOutAttr->pnt();
+
+    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> aProjectedPoint = aFeatureLin->project(aFlyOutPnt);
+    double aDistance = aFlyOutPnt->distance(aProjectedPoint);
+    if (!aFeatureLin->isRight(aFlyOutPnt))
+      aDistance = -aDistance;
+    aFlyout = aDistance;
+  }
 
   //Build dimension here
   boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y());
index b911ea9a424deac698808b85a683d87e34a47572..dac5f926b3824aa66eefcaf3f7237fe8d296f549 100644 (file)
@@ -73,22 +73,24 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape(
   // 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;
-
+  double aFlyout = 0;
+  if (aFlyOutAttr->isInitialized()) {
+    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;
+    aFlyout = aDistance;
+  }
   // value
   boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
     boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));