]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Icon for angle constraint is added, execute method is reviewed for working with pre...
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 21 Aug 2015 14:30:40 +0000 (17:30 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 21 Aug 2015 14:30:53 +0000 (17:30 +0300)
src/PartSet/PartSet_icons.qrc
src/PartSet/icons/angle_constr.png [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp
src/SketchPlugin/SketchPlugin_ConstraintAngle.h
src/SketchPlugin/plugin-Sketch.xml

index 2e7928ace2c07dd632f2ccda67436858d07e10b3..c8e47dcd170d5e9cf5527bd4dddaeb8465b431e3 100644 (file)
@@ -60,5 +60,6 @@
      <file>icons/movement.png</file>
      <file>icons/extrusion_cut.png</file>
      <file>icons/extrusion_fuse.png</file>
+     <file>icons/angle_constr.png</file>
  </qresource>
  </RCC>
diff --git a/src/PartSet/icons/angle_constr.png b/src/PartSet/icons/angle_constr.png
new file mode 100644 (file)
index 0000000..1c403b8
Binary files /dev/null and b/src/PartSet/icons/angle_constr.png differ
index fc2df7237bdaff1f5d4e2bf46c68e13c9aa7b8aa..c0ed698126a53234aec892eb543aacf7f001b239 100644 (file)
@@ -38,14 +38,26 @@ void SketchPlugin_ConstraintAngle::initAttributes()
 void SketchPlugin_ConstraintAngle::execute()
 {
   std::shared_ptr<ModelAPI_Data> aData = data();
-  AttributeDoublePtr anAttrValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
-      aData->attribute(SketchPlugin_Constraint::VALUE()));
 
-  if(anAttrValue->isInitialized())
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttrA = aData->refattr(SketchPlugin_Constraint::ENTITY_A());
+  std::shared_ptr<ModelAPI_AttributeRefAttr> anAttrB = aData->refattr(SketchPlugin_Constraint::ENTITY_B());
+  if (!anAttrA->isInitialized() || !anAttrB->isInitialized())
     return;
 
-  double anAngle = calculateAngle();
-  anAttrValue->setValue(anAngle);
+  AttributeDoublePtr anAttrValue = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+      aData->attribute(SketchPlugin_Constraint::VALUE()));
+
+  if (!anAttrValue->isInitialized()) {
+    double anAngle = calculateAngle();
+    anAttrValue->setValue(anAngle);
+  }
+  // the value should to be computed here, not in the getAISObject in order to change the model value
+  // inside the object transaction. This is important for creating a constraint by preselection.
+  // The display of the presentation in this case happens after the transaction commit
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
+  if(!aFlyOutAttr->isInitialized())
+    compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
 }
 
 AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious)
@@ -67,16 +79,16 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious
 
 void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
 {
-  if (theID == SketchPlugin_Constraint::ENTITY_A() || 
-      theID == SketchPlugin_Constraint::ENTITY_B()) {
-    std::shared_ptr<ModelAPI_Data> aData = data();
-    if (!aData)
-      return;
+  std::shared_ptr<ModelAPI_Data> aData = data();
+  if (!aData)
+    return;
   FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
   FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
-    if (!aLineA || !aLineB)
-      return;
+  if (!aLineA || !aLineB)
+    return;
 
+  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
@@ -85,6 +97,7 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
     }
   } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
     // Recalculate flyout point in local coordinates
+    // coordinates are calculated according to the center of shapes intersection
     std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
         std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
   }
@@ -148,3 +161,45 @@ void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY)
   aFlyoutAttr->setValue(aFlyoutAttr->x() + theDeltaX, aFlyoutAttr->y() + theDeltaY);
   myFlyoutUpdate = false;
 }
+
+
+bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId)
+{
+  if (theAttributeId != SketchPlugin_Constraint::FLYOUT_VALUE_PNT())
+    return false;
+  if (!sketch())
+    return false;
+
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyOutAttr = std::dynamic_pointer_cast<
+                           GeomDataAPI_Point2D>(attribute(theAttributeId));
+  if (fabs(aFlyOutAttr->x()) >= tolerance || fabs(aFlyOutAttr->y()) >= tolerance)
+    return false;
+
+  DataPtr aData = data();
+  std::shared_ptr<GeomAPI_Ax3> aPlane = SketchPlugin_Sketch::plane(sketch());
+  FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+  FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+
+  if ((aLineA.get() == NULL) || (aLineB.get() == NULL))
+    return false;
+
+  // Start and end points of lines
+  std::shared_ptr<GeomDataAPI_Point2D> aPointA1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aLineA->attribute(SketchPlugin_Line::START_ID()));
+  std::shared_ptr<GeomDataAPI_Point2D> aPointA2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aLineA->attribute(SketchPlugin_Line::END_ID()));
+
+  std::shared_ptr<GeomAPI_Pnt2d> aStartA = aPointA1->pnt();
+  std::shared_ptr<GeomAPI_Pnt2d> aEndA   = aPointA2->pnt();
+  if (aStartA->distance(aEndA) < tolerance)
+    return false;
+
+  myFlyoutUpdate = true;
+  double aX = (aStartA->x() + aEndA->x()) / 2.;
+  double aY = (aStartA->y() + aEndA->y()) / 2.;
+
+  aFlyOutAttr->setValue(aX, aY);
+  myFlyoutUpdate = false;
+
+  return true;
+}
\ No newline at end of file
index 29f37f82f9678f8ce92356b2969a2a66f16fd725..ef3c478bef927e4e60203e760b41e97a976f3358 100644 (file)
@@ -37,6 +37,11 @@ class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase
   /// \brief Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();
 
+  /// Computes the attribute value on the base of other attributes if the value can be computed
+  /// \param theAttributeId an attribute index to be computed
+  /// \return a boolean value about it is computed
+  SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId);
+
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
index 8418520a855dc6082421f98b200da439cc8b2a53..8468ea0eb730797b82fd8a1e2d642c3291ccbd10 100644 (file)
         <doublevalue_editor label="Value" tooltip="Radius" id="ConstraintValue" default="computed"/>
         <validator id="PartSet_RadiusSelection"/>
       </feature>
-      
-    <!--  SketchConstraintParallel  -->
+
+      <!--  SketchConstraintAngle  -->
+      <feature id="SketchConstraintAngle" title="Angle" tooltip="Set fixed angle between two line segments" icon=":icons/angle_constr.png">
+        <shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line" shape_types="edge" >
+          <validator id="GeomValidators_ShapeType" parameters="line"/>
+          <validator id="PartSet_DifferentObjects"/>
+          <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+        </shape_selector>
+        <shape_selector id="ConstraintEntityB" label="Line" tooltip="Select an line" shape_types="edge" >
+          <validator id="GeomValidators_ShapeType" parameters="line"/>
+          <validator id="PartSet_DifferentObjects"/>
+          <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
+        </shape_selector>
+        <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
+        <doublevalue_editor label="Value" tooltip="Angle" id="ConstraintValue" default="computed" />
+        <validator id="PartSet_AngleSelection"/>
+      </feature>
+
+      <!--  SketchConstraintParallel  -->
       <feature id="SketchConstraintParallel" title="Parallel" tooltip="Create constraint defining two parallel lines" icon=":icons/parallel.png">
         <sketch_shape_selector id="ConstraintEntityA" 
             label="First line" tooltip="Select a line" shape_types="edge">
         </sketch_shape_selector>
         <validator id="PartSet_TangentSelection"/>
       </feature>
-      
-      
-    <!--  SketchConstraintAngle  -->      
-      <feature id="SketchConstraintAngle" title="Angle" tooltip="Set fixed angle between two line segments">
-        <shape_selector id="ConstraintEntityA" label="Line" tooltip="Select an line" shape_types="edge" >
-          <validator id="GeomValidators_ShapeType" parameters="line"/>
-          <validator id="PartSet_DifferentObjects"/>
-          <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
-        </shape_selector>
-        <shape_selector id="ConstraintEntityB" label="Line" tooltip="Select an line" shape_types="edge" >
-          <validator id="GeomValidators_ShapeType" parameters="line"/>
-          <validator id="PartSet_DifferentObjects"/>
-          <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
-        </shape_selector>
-        <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
-        <doublevalue_editor label="Value" tooltip="Angle" id="ConstraintValue" default="computed" />
-        <validator id="PartSet_AngleSelection"/>
-      </feature>
-
          
     </group>