PartSet_OperationFeatureCreate.h
PartSet_OperationSketchBase.h
PartSet_OperationSketch.h
- PartSet_Presentation.h
PartSet_TestOCC.h
PartSet_Tools.h
)
PartSet_OperationFeatureCreate.cpp
PartSet_OperationSketchBase.cpp
PartSet_OperationSketch.cpp
- PartSet_Presentation.cpp
PartSet_TestOCC.cpp
PartSet_Tools.cpp
)
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
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)
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;
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 "";
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;
#include <ModuleBase_WidgetFactory.h>
#include <PartSet_Listener.h>
#include <PartSet_TestOCC.h>
-#include <PartSet_Presentation.h>
#include <ModuleBase_Operation.h>
#include <ModelAPI_Object.h>
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));
+ if (!anAIS.IsNull())
+ aDisplayer->redisplay(theFeature, anAIS, false);
+ }
}
else
aDisplayer->erase(theFeature, false);
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);
+++ /dev/null
-// 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;
-}
+++ /dev/null
-// 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
#include <XGUI_ViewerPrs.h>
#include <XGUI_ViewerProxy.h>
#include <PartSet_FeaturePrs.h>
-#include <PartSet_Presentation.h>
#include <PartSet_Tools.h>
#include <PartSet_OperationSketchBase.h>
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);
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;
SketchPlugin_Point.cpp
SketchPlugin_Circle.cpp
SketchPlugin_Arc.cpp
+ SketchPlugin_Constraint.cpp
SketchPlugin_ConstraintCoincidence.cpp
SketchPlugin_ConstraintDistance.cpp
SketchPlugin_ConstraintLength.cpp
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})
../GeomAPI
../GeomAlgoAPI
../GeomDataAPI
+ ${CAS_INCLUDE_DIRS}
)
INSTALL(TARGETS SketchPlugin DESTINATION plugins)
--- /dev/null
+// 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();
+}
+
#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".
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
{
}
-const boost::shared_ptr<GeomAPI_Shape>& SketchPlugin_ConstraintCoincidence::preview()
-{
- /// \todo Preview for point coincidence
- return getPreview();
-}
-
/// \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();
};
// 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()
{
{
}
-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;
}
/// \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();
// 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()
{
}
{
}
-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;
}
/// \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();
#include <GeomDataAPI_Point2D.h>
#include <SketchPlugin_Point.h>
+#include <AIS_InteractiveObject.hxx>
+
SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius()
{
}
{
}
-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;
}
/// \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();
#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;
}
return mySketch;
}
+
+Handle(AIS_InteractiveObject) SketchPlugin_Feature::getAISShape(Handle(AIS_InteractiveObject) thePrevious)
+{
+ boost::shared_ptr<GeomAPI_Shape> aPreview = preview();
+ if (!aPreview)
+ return thePrevious;
+
+ Handle(AIS_InteractiveObject) anAIS = thePrevious;
+ const TopoDS_Shape& aShape = aPreview->impl<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;
+}
class SketchPlugin_Sketch;
class GeomAPI_Pnt2d;
+class Handle_AIS_InteractiveObject;
/**\class SketchPlugin_Feature
* \ingroup DataModel
/// \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(
#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
#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
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()) {
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()));
+}
#include "SketchPlugin.h"
#include <SketchPlugin_Feature.h>
#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Pln.h>
#include <list>
/// Sketch feature kind
/// 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(
/// 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