]> 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 12:58:41 +0000 (16:58 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 24 Jun 2014 12:58:41 +0000 (16:58 +0400)
Move for line constraint. Do not build line preview until both points are initialized.

src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.h
src/SketchPlugin/SketchPlugin_Line.cpp

index d6e2b0075c7958cdbff8f71c55da53209fbd6f6f..1ff92e3fdb260b0af0aba1b2eb5b5e876e61e512 100644 (file)
@@ -31,16 +31,15 @@ void SketchPlugin_ConstraintDistance::execute()
   boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr_B = 
           boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
 
-  AttributeDoublePtr anAttribute =
+  AttributeDoublePtr anAttr_Value =
       boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-
-  if (anAttr_A && anAttr_B && anAttribute->value() == 0)
+  if (anAttr_A && anAttr_B && !anAttr_Value->isInitialized())
   {
     FeaturePtr aFeature_A = anAttr_A->feature();
     FeaturePtr aFeature_B = anAttr_B->feature();
 
     double aValue = 40; // TODO
-    anAttribute->setValue(aValue);
+    anAttr_Value->setValue(aValue);
   }
 }
 
index 7218a5341a6cafca97d0d5359bb0609bff2207d0..76563c003cb6d1f1869210c0633ea8b76c3d18b5 100644 (file)
@@ -31,3 +31,14 @@ const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintLength::preview(
   return getPreview();
 }
 
+void SketchPlugin_ConstraintLength::move(double theDeltaX, double theDeltaY)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  if (!aData->isValid())
+    return;
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+}
+
index 57a5dbcc61af88b4a4ec1708c7112a382c765835..52719e7652b1510ae4f8b16c4e441a8fbcd2030c 100644 (file)
@@ -41,6 +41,11 @@ public:
   /// \brief Returns the sketch preview
   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
 
+  /// Moves the feature
+  /// \param theDeltaX the delta for X coordinate is moved
+  /// \param theDeltaY the delta for Y coordinate is moved
+  SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintLength();
 };
index 245440e22cebc7f290428e9d6b538f610577b006..f6d97fa21b7059e9b7d7821daebc02f969d3c5a0 100644 (file)
@@ -40,14 +40,16 @@ const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Line::preview()
     // compute a start point in 3D view
     boost::shared_ptr<GeomDataAPI_Point2D> aStartAttr = 
       boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_START));
-    boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
     // compute an end point in 3D view
     boost::shared_ptr<GeomDataAPI_Point2D> anEndAttr = 
       boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(LINE_ATTR_END));
-    boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
-    // make linear edge
-    boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
-    setPreview(anEdge);
+    if (aStartAttr->isInitialized() && anEndAttr->isInitialized()) {
+      boost::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y()));
+      boost::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y()));
+      // make linear edge
+      boost::shared_ptr<GeomAPI_Shape> anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd);
+      setPreview(anEdge);
+    }
   }
   return getPreview();
 }