]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PartSet/PartSet_Presentation.cpp
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_Presentation.cpp
index a89383a7a02a7d049b52551bfcbe58727c9659c4..5d174047b4f3495dc85ede5968d66a32bb2f4b74 100644 (file)
@@ -5,44 +5,33 @@
 #include <PartSet_Presentation.h>
 #include <PartSet_Tools.h>
 
-#include <ModelAPI_Feature.h>
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDouble.h>
+#include <PartSet_FeatureLengthPrs.h>
 
-#include <GeomDataAPI_Point.h>
-#include <GeomDataAPI_Point2D.h>
-#include <GeomDataAPI_Dir.h>
+#include <ModelAPI_Feature.h>
 
 #include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_Constraint.h>
-#include <SketchPlugin_ConstraintLength.h>
 
 #include <AIS_InteractiveObject.hxx>
-#include <AIS_LengthDimension.hxx>
 #include <AIS_Shape.hxx>
 
-#include <gp_Pln.hxx>
-#include <gp_Pnt.hxx>
+#include <Quantity_NameOfColor.hxx>
 
 const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color
 const int SKETCH_WIDTH = 4; /// the plane edge width
 
-const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint
-const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance
-
 Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation(
                                          FeaturePtr theFeature,
                                          FeaturePtr theSketch,
                                          const TopoDS_Shape& theShape,
-                                         Handle_AIS_InteractiveObject thePrevPrs)
+                                         Handle_AIS_InteractiveObject thePreviuos)
 {
   Handle(AIS_InteractiveObject) anAIS;
 
-  if (theFeature->getKind() == SKETCH_CONSTRAINT_LENGTH_KIND)
-    anAIS = createSketchConstraintLength(theFeature, theSketch, thePrevPrs);
+  std::string aKind = theFeature->getKind();
+  if (aKind == PartSet_FeatureLengthPrs::getKind())
+    anAIS = PartSet_FeatureLengthPrs::createPresentation(theFeature, theSketch, thePreviuos);
   else {
-    anAIS = createFeature(theFeature, theShape, thePrevPrs);
+    anAIS = createFeature(theFeature, theShape, thePreviuos);
     if (theFeature->getKind() == SKETCH_KIND)
     {
       Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
@@ -58,9 +47,9 @@ Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation(
 Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature(
                                               FeaturePtr theFeature,
                                               const TopoDS_Shape& theShape,
-                                              Handle_AIS_InteractiveObject thePrevPrs)
+                                              Handle_AIS_InteractiveObject thePreviuos)
 {
-  Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
+  Handle(AIS_InteractiveObject) anAIS = thePreviuos;
   if (!anAIS.IsNull())
   {
     Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
@@ -80,87 +69,3 @@ Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature(
   }
   return anAIS;
 }
-
-Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength(
-                                         FeaturePtr theFeature,
-                                         FeaturePtr theSketch,
-                                         Handle(AIS_InteractiveObject) thePrevPrs)
-{
-  if (!theFeature || !theSketch)
-    return thePrevPrs;
-
-  boost::shared_ptr<ModelAPI_Data> aData = theSketch->data();
-  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Point>(aData->attribute(SKETCH_ATTR_ORIGIN));
-  boost::shared_ptr<GeomDataAPI_Dir> aNormal = 
-    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SKETCH_ATTR_NORM));
-  gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/);
-
-  aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
-  if (!anAttr)
-    return thePrevPrs;
-  FeaturePtr aFeature = anAttr->feature();
-  if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
-    return thePrevPrs;
-
-  boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-  double aFlyout = aFlyoutAttr->value();
-
-  aData = aFeature->data();
-  if (!aData->isValid())
-    return thePrevPrs;
-
-  boost::shared_ptr<GeomDataAPI_Point2D> aPointStart =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_START));
-  boost::shared_ptr<GeomDataAPI_Point2D> aPointEnd =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
-
-  gp_Pnt aPoint1, aPoint2;
-  PartSet_Tools::convertTo3D(aPointStart->x(), aPointStart->y(), theSketch, aPoint1);
-  PartSet_Tools::convertTo3D(aPointEnd->x(), aPointEnd->y(), theSketch, aPoint2);
-
-  //Build dimension here
-  gp_Pnt aP1 = aPoint1;
-  gp_Pnt aP2 = aPoint2;
-  if (aFlyout < 0) {
-    aP1 = aPoint2;
-    aP2 = aPoint1;
-  }
-
-
-  Handle(AIS_InteractiveObject) anAIS = thePrevPrs;
-  if (anAIS.IsNull())
-  {
-    Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane);
-
-    Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
-    anAspect->MakeArrows3d (Standard_False);
-    anAspect->MakeText3d(false/*is text 3d*/);
-    anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
-    anAspect->MakeTextShaded(false/*is test shaded*/);
-    aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/);
-    /*if (isUnitsDisplayed)
-    {
-      aDimAIS->SetDisplayUnits (aDimDlg->GetUnits ());
-    }*/
-    aDimAIS->SetDimensionAspect (anAspect);
-    aDimAIS->SetFlyout(aFlyout);
-    aDimAIS->SetSelToleranceForText2d(CONSTRAINT_TEXT_SELECTION_TOLERANCE);
-
-    anAIS = aDimAIS;
-  }
-  else {
-    // update presentation
-    Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS);
-    if (!aDimAIS.IsNull()) {
-      aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane);
-      aDimAIS->SetFlyout(aFlyout);
-
-      aDimAIS->Redisplay(Standard_True);
-    }
-  }
-  return anAIS;
-}