From: azv Date: Tue, 24 Jun 2014 12:28:37 +0000 (+0400) Subject: Move generation of AIS presentation into SketchPlugin X-Git-Tag: V_0.4.4~256^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=29dc792755900920f8d355a87dd0c31fd26bfe50;p=modules%2Fshaper.git Move generation of AIS presentation into SketchPlugin --- diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index e8e2647a8..c720df329 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -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 ) diff --git a/src/PartSet/PartSet_Constants.h b/src/PartSet/PartSet_Constants.h index 9f466ed55..f55b58048 100644 --- a/src/PartSet/PartSet_Constants.h +++ b/src/PartSet/PartSet_Constants.h @@ -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 diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.cpp b/src/PartSet/PartSet_ConstraintDistancePrs.cpp index 661061efd..de3310431 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.cpp +++ b/src/PartSet/PartSet_ConstraintDistancePrs.cpp @@ -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 aGPlane = PartSet_Tools::sketchPlane(theSketch); - gp_Pln aPlane = aGPlane->impl(); - - boost::shared_ptr aPoint_A = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_A); - boost::shared_ptr aPoint_B = getFeaturePoint(theFeature, CONSTRAINT_ATTR_ENTITY_B); - if (!aPoint_A || !aPoint_B) - return anAIS; - - // fly out calculation - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr aFlyOutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); - boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); - - boost::shared_ptr aFeatureLin = boost::shared_ptr - (new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), - aPoint_B->x(), aPoint_B->y())); - boost::shared_ptr 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 aValueAttr = - boost::dynamic_pointer_cast(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 PartSet_ConstraintDistancePrs::getFeaturePoint (FeaturePtr theFeature, const std::string& theAttribute) diff --git a/src/PartSet/PartSet_ConstraintDistancePrs.h b/src/PartSet/PartSet_ConstraintDistancePrs.h index 4b957e007..30c6923a5 100644 --- a/src/PartSet/PartSet_ConstraintDistancePrs.h +++ b/src/PartSet/PartSet_ConstraintDistancePrs.h @@ -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; diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.cpp b/src/PartSet/PartSet_ConstraintLengthPrs.cpp index b866ff2e8..67b989c3b 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.cpp +++ b/src/PartSet/PartSet_ConstraintLengthPrs.cpp @@ -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 aGPlane = PartSet_Tools::sketchPlane(theSketch); - gp_Pln aPlane = aGPlane->impl(); - - boost::shared_ptr aData = theFeature->data(); - boost::shared_ptr anAttr = - boost::dynamic_pointer_cast(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 aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - double aFlyout = aFlyoutAttr->value(); - - boost::shared_ptr aValueAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); - double aValue = aValueAttr->value(); - - aData = aFeature->data(); - if (!aData->isValid()) - return thePreviuos; - - boost::shared_ptr aPointStart = - boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); - boost::shared_ptr aPointEnd = - boost::dynamic_pointer_cast(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 ""; diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.h b/src/PartSet/PartSet_ConstraintLengthPrs.h index a8d5a03cf..ba1db99f4 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.h +++ b/src/PartSet/PartSet_ConstraintLengthPrs.h @@ -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; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index e0cf39292..409b8d7ef 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -433,13 +432,13 @@ void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay, XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { - boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); - Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( - theFeature, aPreviewOp->sketch(), - aPreview ? aPreview->impl() : TopoDS_Shape(), - aDisplayer->getAISObject(theFeature)); - - aDisplayer->redisplay(theFeature, anAIS, false); + boost::shared_ptr aSPFeature = + boost::dynamic_pointer_cast(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 aPreview = (*anIt).second; - Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( - aFeature, aPreviewOp->sketch(), - aPreview ? aPreview->impl() : TopoDS_Shape(), - aDisplayer->getAISObject(aFeature)); + boost::shared_ptr aSPFeature = + boost::dynamic_pointer_cast((*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 index 09ecbaa65..000000000 --- a/src/PartSet/PartSet_Presentation.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// File: PartSet_Presentation.h -// Created: 02 June 2014 -// Author: Natalia ERMOLAEVA - -#include -#include - -#include -#include -#include - -#include - -#include - -#include -#include - -#include - -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 index 1e11bb578..000000000 --- a/src/PartSet/PartSet_Presentation.h +++ /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 - -#include - -#include - -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 diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index 9dd77583a..0ca4d5b6e 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -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(), NULL); + boost::shared_ptr aSPFeature = + boost::dynamic_pointer_cast(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 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(), - aPrevAIS); + boost::shared_ptr aSPFeature = + boost::dynamic_pointer_cast(aFeature); + Handle(AIS_InteractiveObject) anAIS = aSPFeature->getAISShape(aPrevAIS); if (!anAIS.IsNull()) theWorkshop->displayer()->redisplay(aFeature, anAIS, true); //std::list aModes; diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 5c0f982e9..1533afdda 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -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 index 000000000..70a980aec --- /dev/null +++ b/src/SketchPlugin/SketchPlugin_Constraint.cpp @@ -0,0 +1,18 @@ +// File: SketchPlugin_Constraint.cpp +// Created: 08 May 2014 +// Author: Artem ZHIDKOV + +#include "SketchPlugin_Constraint.h" + +#include + +Handle_AIS_InteractiveObject SketchPlugin_Constraint::getAISShape(Handle_AIS_InteractiveObject thePrevious) +{ + return thePrevious; +} + +const boost::shared_ptr& SketchPlugin_Constraint::preview() +{ + return getPreview(); +} + diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index dbb66522a..50abf8636 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -12,6 +12,10 @@ #include #include +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& 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 diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp index 6cd5c1b58..e052d1ace 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp @@ -22,9 +22,3 @@ void SketchPlugin_ConstraintCoincidence::execute() { } -const boost::shared_ptr& SketchPlugin_ConstraintCoincidence::preview() -{ - /// \todo Preview for point coincidence - return getPreview(); -} - diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h index 5da46cf88..9ed0e9653 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h @@ -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& preview(); - /// \brief Use plugin manager for features creation SketchPlugin_ConstraintCoincidence(); }; diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index afb764a5d..b6ddb808a 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -3,12 +3,24 @@ // Author: Artem ZHIDKOV #include "SketchPlugin_ConstraintDistance.h" +#include -#include "GeomDataAPI_Point2D.h" +#include +#include +#include #include #include -#include + +#include +#include +#include + +/// Obtain the point object from specified constraint parameter +static boost::shared_ptr getFeaturePoint( + DataPtr theData, + const std::string& theAttribute); + SketchPlugin_ConstraintDistance::SketchPlugin_ConstraintDistance() { @@ -26,9 +38,100 @@ void SketchPlugin_ConstraintDistance::execute() { } -const boost::shared_ptr& 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 aPlane = sketch()->plane(); + + DataPtr aData = data(); + boost::shared_ptr aPoint_A = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_A); + boost::shared_ptr aPoint_B = getFeaturePoint(aData, CONSTRAINT_ATTR_ENTITY_B); + if (!aPoint_A || !aPoint_B) + return thePrevious; + + // fly out calculation + boost::shared_ptr aFlyOutAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); + + boost::shared_ptr aFeatureLin = + boost::shared_ptr(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), + aPoint_B->x(), aPoint_B->y())); + boost::shared_ptr aResult = aFeatureLin->project(aFlyOutPnt); + double aDistance = aFlyOutPnt->distance(aResult); + + if (!aFeatureLin->isRight(aFlyOutPnt)) + aDistance = -aDistance; + double aFlyout = aDistance; + + //Build dimension here + boost::shared_ptr aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y()); + boost::shared_ptr aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y()); + if (aFlyout < 0) + aPoint1.swap(aPoint2); + + // value calculation + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(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(), aPoint2->impl(), aPlane->impl()); + 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(), aPoint2->impl(), aPlane->impl()); + aDimAIS->SetCustomValue(aValue); + aDimAIS->SetFlyout(aFlyout); + + aDimAIS->Redisplay(Standard_True); + } + } + return anAIS; +} + + +boost::shared_ptr getFeaturePoint(DataPtr theData, + const std::string& theAttribute) +{ + boost::shared_ptr aPointAttr; + + if (!theData) + return aPointAttr; + + FeaturePtr aFeature; + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(theData->attribute(theAttribute)); + if (anAttr) + aFeature = anAttr->feature(); + + if (aFeature && aFeature->getKind() == SKETCH_POINT_KIND) + aPointAttr = boost::dynamic_pointer_cast + (aFeature->data()->attribute(POINT_ATTR_COORD)); + return aPointAttr; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 1a90e2dd3..0f04d74e6 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -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& 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(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index b5fe8fca3..4ec9e30ce 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -3,10 +3,17 @@ // Author: Artem ZHIDKOV #include "SketchPlugin_ConstraintLength.h" +#include #include #include +#include + +#include +#include +#include + SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength() { } @@ -22,9 +29,81 @@ void SketchPlugin_ConstraintLength::execute() { } -const boost::shared_ptr& 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 aPlane = sketch()->plane(); + + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(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 aFlyoutAttr = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + double aFlyout = aFlyoutAttr->value(); + + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); + double aValue = aValueAttr->value(); + + boost::shared_ptr aData = aFeature->data(); + if (!aData->isValid()) + return thePrevious; + + boost::shared_ptr aPointStart = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_START)); + boost::shared_ptr aPointEnd = + boost::dynamic_pointer_cast(aData->attribute(LINE_ATTR_END)); + + //Build dimension here + boost::shared_ptr aPoint1 = sketch()->to3D(aPointStart->x(), aPointStart->y()); + boost::shared_ptr 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(), aPoint2->impl(), aPlane->impl()); + 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(), aPoint2->impl(), aPlane->impl()); + aDimAIS->SetCustomValue(aValue); + aDimAIS->SetFlyout(aFlyout); + + aDimAIS->Redisplay(Standard_True); + } + } + return anAIS; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.h b/src/SketchPlugin/SketchPlugin_ConstraintLength.h index 57a5dbcc6..28e3627c3 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.h @@ -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& 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(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index f56b89769..f46792385 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -9,6 +9,8 @@ #include #include +#include + SketchPlugin_ConstraintRadius::SketchPlugin_ConstraintRadius() { } @@ -26,9 +28,10 @@ void SketchPlugin_ConstraintRadius::execute() { } -const boost::shared_ptr& SketchPlugin_ConstraintRadius::preview() +Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( + Handle_AIS_InteractiveObject thePrevious) { /// \todo Preview for diameter constraint - return getPreview(); + return thePrevious; } diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index fb39f7bc3..7af115ce9 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -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& 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(); diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 7bda5720b..6a7e12f5d 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -5,6 +5,10 @@ #include #include +#include +#include +#include + 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 aPreview = preview(); + + Handle(AIS_InteractiveObject) anAIS = thePrevious; + const TopoDS_Shape& aShape = aPreview ? 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; +} diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 5563c9013..084763958 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -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& 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( diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index 245440e22..ee98b3724 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -13,6 +13,8 @@ #include #include +#include + using namespace std; // face of the square-face displayed for selection of general plane diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 51e9bbff6..81ead9d7d 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -12,6 +12,14 @@ #include #include +#include +#include + +#include + +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& 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 SketchPlugin_Sketch::plane() +{ + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aNorm = + boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_NORM)); + + if (!anOrigin || !aNorm) + return boost::shared_ptr(); + + return boost::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); +} diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 7470d7161..1f16d72ca 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -8,6 +8,7 @@ #include "SketchPlugin.h" #include #include +#include #include /// Sketch feature kind @@ -48,6 +49,9 @@ public: /// Returns the sketch preview SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr& 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 plane(); protected: /// Creates a plane and append it to the list /// \param theX the X normal value