]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Update SketchPlugin_Projection feature (issue #1459)
authorazv <azv@opencascade.com>
Wed, 27 Apr 2016 11:05:20 +0000 (14:05 +0300)
committerazv <azv@opencascade.com>
Wed, 27 Apr 2016 11:05:20 +0000 (14:05 +0300)
src/SketchPlugin/SketchPlugin_Projection.cpp
src/SketchPlugin/plugin-Sketch.xml

index 9adacbb6790aa652d75ade054373e0c72e20c021..6240c933b2b54e2682e1ed1de001b46d54fe25bb 100644 (file)
@@ -10,6 +10,7 @@
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_ConstraintRigid.h>
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeSelection.h>
@@ -55,7 +56,7 @@ void SketchPlugin_Projection::execute()
 
   if (!lastResult().get()) {
     ResultConstructionPtr aConstr = document()->createConstruction(data());
-    aConstr->setShape(std::shared_ptr<GeomAPI_Edge>());
+    aConstr->setShape(aProjection->lastResult()->shape());
     aConstr->setIsInHistory(false);
     setResult(aConstr);
 
@@ -75,6 +76,16 @@ void SketchPlugin_Projection::attributeChanged(const std::string& theID)
     computeProjection(theID);
     myIsComputing = false;
   }
+  else if (theID == AUXILIARY_ID())
+  {
+    AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
+    if (!aRefAttr || !aRefAttr->isInitialized())
+      return;
+    FeaturePtr aProjection = ModelAPI_Feature::feature(aRefAttr->object());
+    if (!aProjection)
+      return;
+    aProjection->boolean(AUXILIARY_ID())->setValue(boolean(AUXILIARY_ID())->value());
+  }
 }
 
 void SketchPlugin_Projection::computeProjection(const std::string& theID)
@@ -97,7 +108,8 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     aProjection = ModelAPI_Feature::feature(aRefAttr->object());
 
   // if the type of feature differs with already selected, remove it and create once again
-  if (aProjection) {
+  bool hasPrevProj = aProjection.get() != 0;
+  if (hasPrevProj) {
     if ((anEdge->isLine() && aProjection->getKind() != SketchPlugin_Line::ID()) ||
         (anEdge->isCircle() && aProjection->getKind() != SketchPlugin_Circle::ID()) ||
         (anEdge->isArc() && aProjection->getKind() != SketchPlugin_Arc::ID())) {
@@ -119,7 +131,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     if (aFirstInSketch->distance(aLastInSketch) < tolerance)
       return; // line is semi-orthogonal to the sketch plane
 
-    if (!aProjection)
+    if (!hasPrevProj)
       aProjection = sketch()->addFeature(SketchPlugin_Line::ID());
 
     // update attributes of projection
@@ -137,7 +149,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     std::shared_ptr<GeomAPI_Pnt> aCenter = aSketchPlane->project(aCircle->center());
     std::shared_ptr<GeomAPI_Pnt2d> aCenterInSketch = sketch()->to2D(aCenter);
 
-    if (!aProjection)
+    if (!hasPrevProj)
       aProjection = sketch()->addFeature(SketchPlugin_Circle::ID());
 
     // update attributes of projection
@@ -156,7 +168,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     std::shared_ptr<GeomAPI_Pnt> aCenter = aSketchPlane->project(aCircle->center());
     std::shared_ptr<GeomAPI_Pnt2d> aCenterInSketch = sketch()->to2D(aCenter);
 
-    if (!aProjection)
+    if (!hasPrevProj)
       aProjection = sketch()->addFeature(SketchPlugin_Arc::ID());
 
     // update attributes of projection
@@ -174,6 +186,12 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
   aProjection->execute();
   aRefAttr->setObject(aProjection);
 
+  if (!hasPrevProj) {
+    FeaturePtr aFixed = sketch()->addFeature(SketchPlugin_ConstraintRigid::ID());
+    aFixed->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(aProjection->lastResult());
+    aFixed->execute();
+  }
+
   if (theID == EXTERNAL_FEATURE_ID())
     selection(EXTERNAL_ID())->setValue(aExtFeature->context(), aExtFeature->context()->shape());
 }
index 592f7503def0a01bf4435b921a30bf7787fce94b..dab490931354c0eabf96a90d63f9a3389b58fa44 100644 (file)
               label="Edge"
               tooltip="Select external edge."
               shape_types="edge"
+              use_external="false"
               use_sketch_plane="false">
           <validator id="SketchPlugin_ProjectionValidator"/>
         </sketch_shape_selector>