]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Move generation of AIS presentation into SketchPlugin
authorazv <azv@opencascade.com>
Tue, 24 Jun 2014 12:28:37 +0000 (16:28 +0400)
committerazv <azv@opencascade.com>
Tue, 24 Jun 2014 12:51:09 +0000 (16:51 +0400)
26 files changed:
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Constants.h
src/PartSet/PartSet_ConstraintDistancePrs.cpp
src/PartSet/PartSet_ConstraintDistancePrs.h
src/PartSet/PartSet_ConstraintLengthPrs.cpp
src/PartSet/PartSet_ConstraintLengthPrs.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Presentation.cpp [deleted file]
src/PartSet/PartSet_Presentation.h [deleted file]
src/PartSet/PartSet_TestOCC.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Constraint.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Constraint.h
src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp
src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h
src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp
src/SketchPlugin/SketchPlugin_ConstraintDistance.h
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.h
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp
src/SketchPlugin/SketchPlugin_ConstraintRadius.h
src/SketchPlugin/SketchPlugin_Feature.cpp
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index e8e2647a89fe2c35bd9e4ad2172b0e35d4cf2c4d..c720df3298132fa8c7de980142ec45ef4a1c99a6 100644 (file)
@@ -23,7 +23,6 @@ SET(PROJECT_HEADERS
        PartSet_OperationFeatureCreate.h
        PartSet_OperationSketchBase.h
        PartSet_OperationSketch.h
-       PartSet_Presentation.h
        PartSet_TestOCC.h
        PartSet_Tools.h
 )
@@ -47,7 +46,6 @@ SET(PROJECT_SOURCES
        PartSet_OperationFeatureCreate.cpp
        PartSet_OperationSketchBase.cpp
        PartSet_OperationSketch.cpp
-       PartSet_Presentation.cpp
        PartSet_TestOCC.cpp
        PartSet_Tools.cpp
 )
index 9f466ed55c88c6e9ca13700bd27fc49a187e7f1f..f55b58048ac9a6cf20b3f6a946ded91eebd2e631 100644 (file)
@@ -19,7 +19,7 @@ enum PartSet_SelectionMode
   SM_DonePoint
 };
 
-const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint
-const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance
+////const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint
+////const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance
 
 #endif
index 661061efd2da5e47baa6aba2c3459ec541d0c244..de33104313347ebb60f5885b84c46d0b7679127e 100644 (file)
@@ -102,88 +102,6 @@ PartSet_SelectionMode PartSet_ConstraintDistancePrs::setPoint(double theX, doubl
   return aMode;
 }
 
-Handle(AIS_InteractiveObject) PartSet_ConstraintDistancePrs::createPresentation(FeaturePtr theFeature,
-                                                       FeaturePtr theSketch,
-                                                       Handle(AIS_InteractiveObject) thePreviuos)
-{
-  Handle(AIS_InteractiveObject) anAIS = thePreviuos;
-  if (!theFeature || !theSketch)
-    return anAIS;
-  boost::shared_ptr<GeomAPI_Pln> aGPlane = PartSet_Tools::sketchPlane(theSketch);
-  gp_Pln aPlane = aGPlane->impl<gp_Pln>();
-
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_A);
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_B);
-  if (!aPoint_A || !aPoint_B)
-    return anAIS;
-
-  // fly out calculation
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  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> aResult = aFeatureLin->project(aFlyOutPnt);
-  double aDistance = aFlyOutPnt->distance(aResult);
-
-  if (!aFeatureLin->isRight(aFlyOutPnt))
-    aDistance = -aDistance;
-  double aFlyout = aDistance;
-
-  gp_Pnt aPoint1, aPoint2;
-  PartSet_Tools::convertTo3D(aPoint_A->x(), aPoint_A->y(), theSketch, aPoint1);
-  PartSet_Tools::convertTo3D(aPoint_B->x(), aPoint_B->y(), theSketch, aPoint2);
-
-  //Build dimension here
-  gp_Pnt aP1 = aPoint1;
-  gp_Pnt aP2 = aPoint2;
-  if (aFlyout < 0) {
-    aP1 = aPoint2;
-    aP2 = aPoint1;
-  }
-
-  // value calculation
-  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
-         boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-  double aValue = aValueAttr->value();
-  if (aValue == 0) { // TODO! the default value
-    aValue = aP1.Distance(aP2);
-  }
-
-  if (anAIS.IsNull())
-  {
-    Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension(aP1, aP2, aPlane);
-    aDimAIS->SetCustomValue(aValue);
-
-    Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
-    anAspect->MakeArrows3d (Standard_False);
-    anAspect->MakeText3d(false);
-    anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
-    anAspect->MakeTextShaded(false);
-    aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
-    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->SetCustomValue(aValue);
-      aDimAIS->SetFlyout(aFlyout);
-
-      aDimAIS->Redisplay(Standard_True);
-    }
-  }
-  return anAIS;
-}
-
 boost::shared_ptr<GeomDataAPI_Point2D> PartSet_ConstraintDistancePrs::getFeaturePoint
                                                                (FeaturePtr theFeature,
                                                                 const std::string& theAttribute)
index 4b957e007139ed631575e7d6dd5de84e91e0915e..30c6923a521eadde2e9d03e973f08c65ed88b9ec 100644 (file)
@@ -46,15 +46,6 @@ public:
   virtual PartSet_SelectionMode setPoint(double theX, double theY,
                                          const PartSet_SelectionMode& theMode);
 
-  /// Creates an AIS presentation if the previous is null or update the given one
-  /// \param theFeature a feature
-  /// \param theSketch a feature sketch
-  /// \param thePrevious a previuos AIS presentation
-  /// \return a created/changed AIS object with the feature parameters
-  static Handle_AIS_InteractiveObject createPresentation(FeaturePtr theFeature,
-                                                         FeaturePtr theSketch,
-                                                         Handle_AIS_InteractiveObject thePreviuos);
-
   /// Returns the feature attribute name for the selection mode
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
   virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const;
index b866ff2e8c4ac76a35c81a14335d9123f3045e11..67b989c3be4e25f99a25b48471a035cea55c4c83 100644 (file)
@@ -110,90 +110,6 @@ PartSet_SelectionMode PartSet_ConstraintLengthPrs::setPoint(double theX, double
   return aMode;
 }
 
-Handle(AIS_InteractiveObject) PartSet_ConstraintLengthPrs::createPresentation(FeaturePtr theFeature,
-                                                       FeaturePtr theSketch,
-                                                       Handle(AIS_InteractiveObject) thePreviuos)
-{
-  if (!theFeature || !theSketch)
-    return thePreviuos;
-
-  boost::shared_ptr<GeomAPI_Pln> aGPlane = PartSet_Tools::sketchPlane(theSketch);
-  gp_Pln aPlane = aGPlane->impl<gp_Pln>();
-
-  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
-  if (!anAttr)
-    return thePreviuos;
-  FeaturePtr aFeature = anAttr->feature();
-  if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
-    return thePreviuos;
-
-  boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
-  double aFlyout = aFlyoutAttr->value();
-
-  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
-          boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
-  double aValue = aValueAttr->value();
-
-  aData = aFeature->data();
-  if (!aData->isValid())
-    return thePreviuos;
-
-  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 = thePreviuos;
-  if (anAIS.IsNull())
-  {
-    Handle(AIS_LengthDimension) aDimAIS = new AIS_LengthDimension (aP1, aP2, aPlane);
-    aDimAIS->SetCustomValue(aValue);
-
-    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->SetCustomValue(aValue);
-      aDimAIS->SetFlyout(aFlyout);
-
-      aDimAIS->Redisplay(Standard_True);
-    }
-  }
-  return anAIS;
-}
-
 std::string PartSet_ConstraintLengthPrs::getAttribute(const PartSet_SelectionMode& theMode) const
 {
   return "";
index a8d5a03cff29d10335af169e7d17ebcd8a7c1d85..ba1db99f49dcc2e71b70360714b31d1cde399aa5 100644 (file)
@@ -46,15 +46,6 @@ public:
   virtual PartSet_SelectionMode setPoint(double theX, double theY,
                                          const PartSet_SelectionMode& theMode);
 
-  /// Creates an AIS presentation if the previous is null or update the given one
-  /// \param theFeature a feature
-  /// \param theSketch a feature sketch
-  /// \param thePrevious a previuos AIS presentation
-  /// \return a created/changed AIS object with the feature parameters
-  static Handle_AIS_InteractiveObject createPresentation(FeaturePtr theFeature,
-                                                         FeaturePtr theSketch,
-                                                         Handle_AIS_InteractiveObject thePreviuos);
-
   /// Returns the feature attribute name for the selection mode
   /// \param theMode the current operation selection mode. The feature attribute depends on the mode
   virtual std::string getAttribute(const PartSet_SelectionMode& theMode) const;
index e0cf39292fb895386eeba5854d5128c545fb09cc..409b8d7efad5eebd532a67510264a018136d4d62 100644 (file)
@@ -10,7 +10,6 @@
 #include <ModuleBase_WidgetFactory.h>
 #include <PartSet_Listener.h>
 #include <PartSet_TestOCC.h>
-#include <PartSet_Presentation.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModelAPI_Object.h>
@@ -433,13 +432,13 @@ void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
 
   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
   if (isDisplay) {
-    boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
-    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
-                           theFeature, aPreviewOp->sketch(),
-                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
-                           aDisplayer->getAISObject(theFeature));
-
-    aDisplayer->redisplay(theFeature, anAIS, false);
+    boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+      boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
+    if (aSPFeature)
+    {
+      Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(aDisplayer->getAISObject(theFeature));
+      aDisplayer->redisplay(theFeature, anAIS, false);
+    }
   }
   else
     aDisplayer->erase(theFeature, false);
@@ -481,11 +480,12 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
                                                          anIt = aList.begin(), aLast = aList.end();
   for (; anIt != aLast; anIt++) {
     FeaturePtr aFeature = (*anIt).first;
-    boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
-    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
-                           aFeature, aPreviewOp->sketch(),
-                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
-                           aDisplayer->getAISObject(aFeature));
+    boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+      boost::dynamic_pointer_cast<SketchPlugin_Feature>((*anIt).first);
+    if (!aSPFeature)
+      continue;
+
+    Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(aDisplayer->getAISObject(aFeature));
     if (!anAIS.IsNull())
       aDisplayer->redisplay(aFeature, anAIS, false);
     aDisplayer->activateInLocalContext(aFeature, aModes, false);
diff --git a/src/PartSet/PartSet_Presentation.cpp b/src/PartSet/PartSet_Presentation.cpp
deleted file mode 100644 (file)
index 09ecbaa..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-// File:        PartSet_Presentation.h
-// Created:     02 June 2014
-// Author:      Natalia ERMOLAEVA
-
-#include <PartSet_Presentation.h>
-#include <PartSet_Tools.h>
-
-#include <PartSet_ConstraintLengthPrs.h>
-#include <PartSet_ConstraintDistancePrs.h>
-#include <PartSet_ConstraintRadiusPrs.h>
-
-#include <ModelAPI_Feature.h>
-
-#include <SketchPlugin_Sketch.h>
-
-#include <AIS_InteractiveObject.hxx>
-#include <AIS_Shape.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
-
-Handle(AIS_InteractiveObject) PartSet_Presentation::createPresentation(
-                                         FeaturePtr theFeature,
-                                         FeaturePtr theSketch,
-                                         const TopoDS_Shape& theShape,
-                                         Handle_AIS_InteractiveObject thePreviuos)
-{
-  Handle(AIS_InteractiveObject) anAIS;
-
-  std::string aKind = theFeature->getKind();
-  if (aKind == PartSet_ConstraintLengthPrs::getKind())
-    anAIS = PartSet_ConstraintLengthPrs::createPresentation(theFeature, theSketch, thePreviuos);
-  else if (aKind == PartSet_ConstraintDistancePrs::getKind())
-    anAIS = PartSet_ConstraintDistancePrs::createPresentation(theFeature, theSketch, thePreviuos);
-  else if (aKind == PartSet_ConstraintRadiusPrs::getKind())
-    anAIS = PartSet_ConstraintRadiusPrs::createPresentation(theFeature, theSketch, thePreviuos);
-  else {
-    anAIS = createFeature(theFeature, theShape, thePreviuos);
-    if (theFeature->getKind() == SKETCH_KIND)
-    {
-      Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
-      aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
-      aShapeAIS->SetWidth(SKETCH_WIDTH);
-      aShapeAIS->Redisplay();
-    }
-  }
-
-  return anAIS;
-}
-
-Handle(AIS_InteractiveObject) PartSet_Presentation::createFeature(
-                                              FeaturePtr theFeature,
-                                              const TopoDS_Shape& theShape,
-                                              Handle_AIS_InteractiveObject thePreviuos)
-{
-  Handle(AIS_InteractiveObject) anAIS = thePreviuos;
-  if (!anAIS.IsNull())
-  {
-    Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
-    if (!aShapeAIS.IsNull()) {
-      // if the AIS object is displayed in the opened local context in some mode, additional
-      // AIS sub objects are created there. They should be rebuild for correct selecting.
-      // It is possible to correct it by closing local context before the shape set and opening
-      // after. Another workaround to thrown down the selection and reselecting the AIS.
-      // If there was a problem here, try the first solution with close/open local context.
-      aShapeAIS->Set(theShape);
-      aShapeAIS->Redisplay(Standard_True);
-    }
-  }
-  else
-  {
-    anAIS = new AIS_Shape(theShape);
-  }
-  return anAIS;
-}
diff --git a/src/PartSet/PartSet_Presentation.h b/src/PartSet/PartSet_Presentation.h
deleted file mode 100644 (file)
index 1e11bb5..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// File:        PartSet_Presentation.h
-// Created:     02 Jun 2014
-// Author:      Natalia ERMOLAEVA
-
-#ifndef PartSet_Presentation_H
-#define PartSet_Presentation_H
-
-#include "PartSet.h"
-
-#include <TopoDS_Shape.hxx>
-
-#include <ModelAPI_Feature.h>
-
-#include <boost/shared_ptr.hpp>
-
-class Handle_AIS_InteractiveObject;
-
-/*!
- \class PartSet_Presentation
- * \brief The operation for the sketch feature creation
-*/
-class PARTSET_EXPORT PartSet_Presentation
-{
-public:
-  /// Creates AIS presentation for the given feature. It deals with features and
-  /// constraints presentations
-  /// \param theFeature a feature
-  /// \param theSketch a feature sketch
-  /// \param theShape a shape of the feature
-  /// \param thePrevious a previous AIS object
-  /// \return a created/changed AIS object with the feature parameters
-  static Handle_AIS_InteractiveObject createPresentation(
-                                              FeaturePtr theFeature,
-                                              FeaturePtr theSketch,
-                                              const TopoDS_Shape& theShape,
-                                              Handle_AIS_InteractiveObject thePreviuos);
-protected:
-  /// Creates AIS presentation based on the given shape
-  /// \param theFeature a feature
-  /// \param theSketch a feature sketch
-  /// \param theShape a shape of the feature
-  /// \param thePrevious a previous AIS object
-  /// \return a created/changed AIS object with the feature parameters
- static Handle_AIS_InteractiveObject createFeature(
-                                              FeaturePtr theFeature,
-                                              const TopoDS_Shape& theShape,
-                                              Handle_AIS_InteractiveObject thePreviuos);
-};
-
-#endif
index 9dd77583a16b30a38a101e53cf1d788d54bf8e00..0ca4d5b6e8562ad780def95d3b2675cea95b3cf7 100644 (file)
@@ -10,7 +10,6 @@
 #include <XGUI_ViewerPrs.h>
 #include <XGUI_ViewerProxy.h>
 #include <PartSet_FeaturePrs.h>
-#include <PartSet_Presentation.h>
 #include <PartSet_Tools.h>
 #include <PartSet_OperationSketchBase.h>
 
@@ -149,9 +148,9 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
 
     XGUI_Displayer* aDisplayer = theWorkshop->displayer();
 
-    Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
-                           aFeature, aSketch,
-                           aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), NULL);
+    boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+      boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+    Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(NULL);
     if (!anAIS.IsNull())
       aDisplayer->redisplay(aFeature, anAIS, false);
 
@@ -205,11 +204,9 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop)
   boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchBase::preview(aFeature);
 
   Handle(AIS_InteractiveObject) aPrevAIS;
-  FeaturePtr aSketch;//NULL
-  Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation(
-                          aFeature, aSketch,
-                          aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
-                          aPrevAIS);
+  boost::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+    boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+  Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(aPrevAIS);
   if (!anAIS.IsNull())
     theWorkshop->displayer()->redisplay(aFeature, anAIS, true);
   //std::list<int> aModes;
index 5c0f982e96249ddbc0e79d328200924c9656b1c2..1533afdda50b5979fb45aee180cb348497a660f1 100644 (file)
@@ -26,6 +26,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_Point.cpp
     SketchPlugin_Circle.cpp
     SketchPlugin_Arc.cpp
+    SketchPlugin_Constraint.cpp
     SketchPlugin_ConstraintCoincidence.cpp
     SketchPlugin_ConstraintDistance.cpp
     SketchPlugin_ConstraintLength.cpp
@@ -38,13 +39,15 @@ SET(PROJECT_LIBRARIES
     GeomAPI
     GeomAlgoAPI
     ModelAPI
+    ${CAS_KERNEL}
+    ${CAS_VIEWER}
 )
 
 SET(XML_RESOURCES
   plugin-Sketch.xml
 )
 
-ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
+ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS} ${CAS_DEFINITIONS})
 ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
 TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES})
 
@@ -53,6 +56,7 @@ INCLUDE_DIRECTORIES(
   ../GeomAPI
   ../GeomAlgoAPI
   ../GeomDataAPI
+  ${CAS_INCLUDE_DIRS}
 )
 
 INSTALL(TARGETS SketchPlugin DESTINATION plugins)
diff --git a/src/SketchPlugin/SketchPlugin_Constraint.cpp b/src/SketchPlugin/SketchPlugin_Constraint.cpp
new file mode 100644 (file)
index 0000000..70a980a
--- /dev/null
@@ -0,0 +1,18 @@
+// File:    SketchPlugin_Constraint.cpp
+// Created: 08 May 2014
+// Author:  Artem ZHIDKOV
+
+#include "SketchPlugin_Constraint.h"
+
+#include <AIS_InteractiveObject.hxx>
+
+Handle_AIS_InteractiveObject SketchPlugin_Constraint::getAISShape(Handle_AIS_InteractiveObject thePrevious)
+{ 
+  return thePrevious;
+}
+
+const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_Constraint::preview()
+{
+  return getPreview();
+}
+
index dbb66522a715558218f6eeabd0c723d9c9d3d046..50abf8636921b4362d84dff745591afcd7fd793c 100644 (file)
 #include <ModelAPI_AttributeRefAttr.h>
 #include <list>
 
+const int CONSTRAINT_TEXT_HEIGHT = 28; /// the text height of the constraint
+const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection tolerance
+
+
 /*  Description: 
  *    Each constraint uses a set of parameters. In the SolveSpace library 
  *    these parameters are named "valA", "ptA", "ptB", "entityA", "entityB". 
@@ -63,6 +67,12 @@ public:
   SKETCHPLUGIN_EXPORT virtual const void addSub(
     const FeaturePtr& theFeature) {}
 
+  /// \brief Returns the sketch preview
+  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
+
   /// Moves the feature
   /// \param theDeltaX the delta for X coordinate is moved
   /// \param theDeltaY the delta for Y coordinate is moved
index 6cd5c1b582cb3c36798bf6e5726285dd2d2fca38..e052d1acee3838ab90e0b28e60d8ce68018a0238 100644 (file)
@@ -22,9 +22,3 @@ void SketchPlugin_ConstraintCoincidence::execute()
 {
 }
 
-const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintCoincidence::preview()
-{
-  /// \todo Preview for point coincidence
-  return getPreview();
-}
-
index 5da46cf8801ae0f1e8f1b3b9d0b32a5e957bd57c..9ed0e9653b6811c249e2f59ad7a7af9ef6c4c46a 100644 (file)
@@ -37,9 +37,6 @@ public:
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// \brief Returns the sketch preview
-  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
-
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintCoincidence();
 };
index afb764a5dcfcc3654075ebf5847136f9b77e1a2c..b6ddb808aa950a4fa3b3a4d95fff1f15d2aad57f 100644 (file)
@@ -3,12 +3,24 @@
 // Author:  Artem ZHIDKOV
 
 #include "SketchPlugin_ConstraintDistance.h"
+#include <SketchPlugin_Point.h>
 
-#include "GeomDataAPI_Point2D.h"
+#include <GeomAPI_Lin2D.h>
+#include <GeomAPI_Pnt2D.h>
+#include <GeomDataAPI_Point2D.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
-#include <SketchPlugin_Point.h>
+
+#include <AIS_LengthDimension.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Pln.hxx>
+
+/// Obtain the point object from specified constraint parameter
+static boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(
+            DataPtr             theData,
+            const std::string&  theAttribute);
+
 
 SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance()
 {
@@ -26,9 +38,100 @@ void SketchPlugin_ConstraintDistance::execute()
 {
 }
 
-const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintDistance::preview()
+Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape(
+  Handle_AIS_InteractiveObject thePrevious)
 {
-  /// \todo Preview for distance constraint
-  return getPreview();
+  if (!sketch())
+    return thePrevious;
+
+  boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+
+  DataPtr aData = data();
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A);
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B);
+  if (!aPoint_A || !aPoint_B)
+    return thePrevious;
+
+  // 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> aResult = aFeatureLin->project(aFlyOutPnt);
+  double aDistance = aFlyOutPnt->distance(aResult);
+
+  if (!aFeatureLin->isRight(aFlyOutPnt))
+    aDistance = -aDistance;
+  double aFlyout = aDistance;
+
+  //Build dimension here
+  boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y());
+  boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y());
+  if (aFlyout < 0)
+    aPoint1.swap(aPoint2);
+
+  // value calculation
+  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+  double aValue = aValueAttr->value();
+  if (aValue == 0) { // TODO! the default value
+    aValue = aPoint1->distance(aPoint2);
+  }
+
+  Handle(AIS_InteractiveObject) anAIS = thePrevious;
+  if (anAIS.IsNull())
+  {
+    Handle(AIS_LengthDimension) aDimAIS = 
+      new AIS_LengthDimension(aPoint1->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
+    aDimAIS->SetCustomValue(aValue);
+
+    Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect();
+    anAspect->MakeArrows3d (Standard_False);
+    anAspect->MakeText3d(false);
+    anAspect->TextAspect()->SetHeight(CONSTRAINT_TEXT_HEIGHT);
+    anAspect->MakeTextShaded(false);
+    aDimAIS->DimensionAspect()->MakeUnitsDisplayed(false);
+    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->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
+      aDimAIS->SetCustomValue(aValue);
+      aDimAIS->SetFlyout(aFlyout);
+
+      aDimAIS->Redisplay(Standard_True);
+    }
+  }
+  return anAIS;
+}
+
+
+boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(DataPtr theData,
+                                                       const std::string& theAttribute)
+{
+  boost::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+
+  if (!theData)
+    return aPointAttr;
+
+  FeaturePtr aFeature;
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
+  if (anAttr)
+    aFeature = anAttr->feature();
+
+  if (aFeature && aFeature->getKind() == SKETCH_POINT_KIND)
+    aPointAttr = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
+                                           (aFeature->data()->attribute(POINT_ATTR_COORD));
+  return aPointAttr;
 }
 
index 1a90e2dd3c5516c3cb585036c0b284d3d074c2cb..0f04d74e6cf3d5edb59a3aca97b2cae253a3669b 100644 (file)
@@ -38,8 +38,8 @@ public:
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// \brief Returns the sketch preview
-  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
 
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintDistance();
index b5fe8fca3e3d126c2b837017d352ced5e515f2e1..4ec9e30ce42a328991b6d668f193a562094b3d5a 100644 (file)
@@ -3,10 +3,17 @@
 // Author:  Artem ZHIDKOV
 
 #include "SketchPlugin_ConstraintLength.h"
+#include <SketchPlugin_Line.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
 
+#include <GeomDataAPI_Point2D.h>
+
+#include <AIS_LengthDimension.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Pln.hxx>
+
 SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength()
 {
 }
@@ -22,9 +29,81 @@ void SketchPlugin_ConstraintLength::execute()
 {
 }
 
-const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintLength::preview()
+Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape(
+  Handle_AIS_InteractiveObject thePrevious)
 {
-  /// \todo Preview for distance constraint
-  return getPreview();
+  if (!sketch())
+    return thePrevious;
+
+  boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  if (!anAttr)
+    return thePrevious;
+  FeaturePtr aFeature = anAttr->feature();
+  if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND)
+    return thePrevious;
+
+  boost::shared_ptr<ModelAPI_AttributeDouble> aFlyoutAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE));
+  double aFlyout = aFlyoutAttr->value();
+
+  boost::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(data()->attribute(CONSTRAINT_ATTR_VALUE));
+  double aValue = aValueAttr->value();
+
+  boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+  if (!aData->isValid())
+    return thePrevious;
+
+  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));
+
+  //Build dimension here
+  boost::shared_ptr<GeomAPI_Pnt> aPoint1 = sketch()->to3D(aPointStart->x(), aPointStart->y());
+  boost::shared_ptr<GeomAPI_Pnt> aPoint2 = sketch()->to3D(aPointEnd->x(),   aPointEnd->y());
+  if (aFlyout < 0)
+    aPoint1.swap(aPoint2);
+
+  Handle(AIS_InteractiveObject) anAIS = thePrevious;
+  if (anAIS.IsNull())
+  {
+    Handle(AIS_LengthDimension) aDimAIS = 
+      new AIS_LengthDimension(aPoint1->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
+    aDimAIS->SetCustomValue(aValue);
+
+    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->impl<gp_Pnt>(), aPoint2->impl<gp_Pnt>(), aPlane->impl<gp_Pln>());
+      aDimAIS->SetCustomValue(aValue);
+      aDimAIS->SetFlyout(aFlyout);
+
+      aDimAIS->Redisplay(Standard_True);
+    }
+  }
+  return anAIS;
 }
 
index 57a5dbcc61af88b4a4ec1708c7112a382c765835..28e3627c3b742f6e334a6cce9fa1cb8c01e86f1c 100644 (file)
@@ -38,8 +38,8 @@ public:
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// \brief Returns the sketch preview
-  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
 
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintLength();
index f56b897697109a519d652d8cfe7e66f0db768441..f467923854add12550a488f6278afeb97e3e7a25 100644 (file)
@@ -9,6 +9,8 @@
 #include <GeomDataAPI_Point2D.h>
 #include <SketchPlugin_Point.h>
 
+#include <AIS_InteractiveObject.hxx>
+
 SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
 {
 }
@@ -26,9 +28,10 @@ void SketchPlugin_ConstraintRadius::execute()
 {
 }
 
-const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintRadius::preview()
+Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
+  Handle_AIS_InteractiveObject thePrevious)
 {
   /// \todo Preview for diameter constraint
-  return getPreview();
+  return thePrevious;
 }
 
index fb39f7bc36153f251bf9e67ec6a6664d67c1f74a..7af115ce9f14651a7a2af1849e87a835c1e523d4 100644 (file)
@@ -41,8 +41,8 @@ public:
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
-  /// \brief Returns the sketch preview
-  SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
 
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintRadius();
index 7bda5720bb0e1fc8bdb0e28705d1a420bd965c88..6a7e12f5d83590a12b2f591d48c5de0aa4e4483a 100644 (file)
@@ -5,6 +5,10 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_AttributeRefList.h>
 
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+#include <TopoDS_Shape.hxx>
+
 SketchPlugin_Feature::SketchPlugin_Feature()
 {
   mySketch = 0;
@@ -43,3 +47,30 @@ SketchPlugin_Sketch* SketchPlugin_Feature::sketch()
   }
   return mySketch;
 }
+
+Handle(AIS_InteractiveObject) SketchPlugin_Feature::getAISShape(Handle(AIS_InteractiveObject) thePrevious)
+{
+  boost::shared_ptr<GeomAPI_Shape> aPreview = preview();
+
+  Handle(AIS_InteractiveObject) anAIS = thePrevious;
+  const TopoDS_Shape& aShape = aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape();
+  if (!anAIS.IsNull())
+  {
+    Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+    if (!aShapeAIS.IsNull()) {
+      // if the AIS object is displayed in the opened local context in some mode, additional
+      // AIS sub objects are created there. They should be rebuild for correct selecting.
+      // It is possible to correct it by closing local context before the shape set and opening
+      // after. Another workaround to thrown down the selection and reselecting the AIS.
+      // If there was a problem here, try the first solution with close/open local context.
+
+      aShapeAIS->Set(aShape);
+      aShapeAIS->Redisplay(Standard_True);
+    }
+  }
+  else
+  {
+    anAIS = new AIS_Shape(aShape);
+  }
+  return anAIS;
+}
index 5563c90135b31b815bb9398b0e2d185a78470395..08476395845b4718e3b2c028a27d435cbe171677 100644 (file)
@@ -11,6 +11,7 @@
 
 class SketchPlugin_Sketch;
 class GeomAPI_Pnt2d;
+class Handle_AIS_InteractiveObject;
 
 /**\class SketchPlugin_Feature
  * \ingroup DataModel
@@ -25,6 +26,9 @@ public:
   /// \return the built preview
   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview() = 0;
 
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
+
   /// Adds sub-feature of the higher level feature (sub-element of the sketch)
   /// \param theFeature sub-feature
   SKETCHPLUGIN_EXPORT virtual const void addSub(
index 245440e22cebc7f290428e9d6b538f610577b006..ee98b3724008d796b41ef343b869f095b54f229b 100644 (file)
@@ -13,6 +13,8 @@
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomDataAPI_Point2D.h>
 
+#include <AIS_InteractiveObject.hxx>
+
 using namespace std;
 
 // face of the square-face displayed for selection of general plane
index 51e9bbff61adec8a42a4cf8eb6d9bd3a3097a489..81ead9d7ded55fffa4dd660608b21e10f8e138dd 100644 (file)
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_SketchBuilder.h>
 
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.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
+
 using namespace std;
 
 // face of the square-face displayed for selection of general plane
@@ -72,6 +80,16 @@ void SketchPlugin_Sketch::execute()
   data()->store(aCompound);
 }
 
+Handle(AIS_InteractiveObject) SketchPlugin_Sketch::getAISShape(Handle(AIS_InteractiveObject) thePrevious)
+{
+  Handle(AIS_InteractiveObject) anAIS = SketchPlugin_Feature::getAISShape(thePrevious);
+  Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
+  aShapeAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR));
+  aShapeAIS->SetWidth(SKETCH_WIDTH);
+  aShapeAIS->Redisplay();
+  return anAIS;
+}
+
 const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_Sketch::preview()
 {
   if (isPlaneSet()) {
@@ -127,3 +145,16 @@ bool SketchPlugin_Sketch::isPlaneSet()
 
   return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
 }
+
+boost::shared_ptr<GeomAPI_Pln> SketchPlugin_Sketch::plane()
+{
+  boost::shared_ptr<GeomDataAPI_Point> anOrigin = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point>(data()->attribute(SKETCH_ATTR_ORIGIN));
+  boost::shared_ptr<GeomDataAPI_Dir> aNorm = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Dir>(data()->attribute(SKETCH_ATTR_NORM));
+
+  if (!anOrigin || !aNorm)
+    return boost::shared_ptr<GeomAPI_Pln>();
+
+  return boost::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
+}
index 7470d716129c75343ab23cbf47c7311335e9c28a..1f16d72ca90f1dfa2e5d5c6c2705eaf699b11d18 100644 (file)
@@ -8,6 +8,7 @@
 #include "SketchPlugin.h"
 #include <SketchPlugin_Feature.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Pln.h>
 #include <list>
 
 /// Sketch feature kind
@@ -48,6 +49,9 @@ public:
   /// Returns the sketch preview
   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
 
+  /// Returns the sketch preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
+
   /// Adds sub-feature of the higher level feature (sub-element of the sketch)
   /// \param theFeature sub-feature
   SKETCHPLUGIN_EXPORT virtual const void addSub(
@@ -71,6 +75,9 @@ public:
 
   /// Use plugin manager for features creation
   SketchPlugin_Sketch();
+
+  /// Returns the basis plane for the sketch
+  boost::shared_ptr<GeomAPI_Pln> plane();
 protected:
   /// Creates a plane and append it to the list
   /// \param theX the X normal value