From 8da742ab694198bf02ffd7c4b876128774fd2c92 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 3 Jun 2014 17:52:48 +0400 Subject: [PATCH] Constraint: Check AIS dimension possibilities. Line edit appears by the text selection in AIS dimension. --- src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_Module.cpp | 27 ++-- src/PartSet/PartSet_OperationConstraint.cpp | 43 +++++- src/PartSet/PartSet_OperationConstraint.h | 10 +- src/PartSet/PartSet_OperationSketch.cpp | 50 +++++-- src/PartSet/PartSet_OperationSketch.h | 13 +- src/PartSet/PartSet_Presentation.cpp | 149 +++++++++++++++++++ src/PartSet/PartSet_Presentation.h | 44 ++++++ src/PartSet/PartSet_TestOCC.cpp | 28 +++- src/PartSet/PartSet_Tools.cpp | 23 +++ src/PartSet/PartSet_Tools.h | 9 ++ src/SketchPlugin/CMakeLists.txt | 10 +- src/SketchPlugin/plugin-Sketch.xml | 8 +- src/SketchSolver/SketchSolver_Constraint.cpp | 5 +- src/XGUI/XGUI_Displayer.cpp | 38 ++--- src/XGUI/XGUI_Displayer.h | 11 +- src/XGUI/XGUI_ViewerPrs.cpp | 25 +++- src/XGUI/XGUI_ViewerPrs.h | 26 +++- 18 files changed, 436 insertions(+), 85 deletions(-) create mode 100644 src/PartSet/PartSet_Presentation.cpp create mode 100644 src/PartSet/PartSet_Presentation.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index a9f0973b2..2644f2a86 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -12,6 +12,7 @@ SET(PROJECT_HEADERS PartSet_OperationSketchBase.h PartSet_OperationSketch.h PartSet_OperationSketchLine.h + PartSet_Presentation.h PartSet_TestOCC.h PartSet_Tools.h ) @@ -24,6 +25,7 @@ SET(PROJECT_SOURCES PartSet_OperationSketchBase.cpp PartSet_OperationSketch.cpp PartSet_OperationSketchLine.cpp + PartSet_Presentation.cpp PartSet_TestOCC.cpp PartSet_Tools.cpp ) diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 739edf06a..8965d350e 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,7 @@ #include #include +#include #include #include @@ -394,15 +396,16 @@ void PartSet_Module::visualizePreview(boost::shared_ptr theFea XGUI_Displayer* aDisplayer = myWorkshop->displayer(); if (isDisplay) { boost::shared_ptr aPreview = aPreviewOp->preview(theFeature); - bool isAISCreated = aDisplayer->Redisplay(theFeature, aPreview ? - aPreview->impl() : TopoDS_Shape(), false); - if (isAISCreated) { - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); - if (aSketchOp) { - Handle(AIS_InteractiveObject) anAIS = aDisplayer->GetAISObject(theFeature); - aSketchOp->correctPresentation(anAIS); - } + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + theFeature, aPreviewOp->sketch(), + aPreview ? aPreview->impl() : TopoDS_Shape(), + aDisplayer->GetAISObject(theFeature)); + + int aSelectionMode = -1; + if (theFeature->getKind() == "SketchConstraintLength") { + aSelectionMode = AIS_DSM_Text; } + aDisplayer->Redisplay(theFeature, anAIS, aSelectionMode, false); } else aDisplayer->Erase(theFeature, false); @@ -447,8 +450,12 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) for (; anIt != aLast; anIt++) { boost::shared_ptr aFeature = (*anIt).first; boost::shared_ptr aPreview = (*anIt).second; - aDisplayer->Redisplay(aFeature, - aPreview ? aPreview->impl() : TopoDS_Shape(), false); + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aPreviewOp->sketch(), + aPreview ? aPreview->impl() : TopoDS_Shape(), + aDisplayer->GetAISObject(aFeature)); + if (!anAIS.IsNull()) + aDisplayer->Redisplay(aFeature, anAIS, -1, false); aDisplayer->ActivateInLocalContext(aFeature, aModes, false); } aDisplayer->UpdateViewer(); diff --git a/src/PartSet/PartSet_OperationConstraint.cpp b/src/PartSet/PartSet_OperationConstraint.cpp index 9f5e5b503..6ad9a3108 100644 --- a/src/PartSet/PartSet_OperationConstraint.cpp +++ b/src/PartSet/PartSet_OperationConstraint.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -91,13 +92,20 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3 bool isFoundPoint = false; gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView); +*/ if (theSelected.empty()) { - PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); - isFoundPoint = true; + //PartSet_Tools::ConvertTo2D(aPoint, sketch(), theView, aX, anY); + //isFoundPoint = true; } else { XGUI_ViewerPrs aPrs = theSelected.front(); - const TopoDS_Shape& aShape = aPrs.shape(); + boost::shared_ptr aFeature = aPrs.feature(); + + setFeature(aFeature); + setValue(120); + flushUpdated(); + + /*const TopoDS_Shape& aShape = aPrs.shape(); if (!aShape.IsNull()) // the point is selected { if (aShape.ShapeType() == TopAbs_VERTEX) { @@ -135,10 +143,10 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3 isFoundPoint = true; } } - } + }*/ } - switch (myPointSelectionMode) + /*switch (myPointSelectionMode) { case SM_FirstPoint: { setLinePoint(feature(), aX, anY, LINE_ATTR_START); @@ -157,8 +165,7 @@ void PartSet_OperationConstraint::mouseReleased(QMouseEvent* theEvent, Handle(V3 break; default: break; - } -*/ + }*/ } void PartSet_OperationConstraint::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) @@ -243,3 +250,25 @@ boost::shared_ptr PartSet_OperationConstraint::createFeature(c flushCreated(); return aNewFeature; } + +void PartSet_OperationConstraint::setFeature(boost::shared_ptr theFeature) +{ + if (!theFeature || theFeature->getKind() != "SketchLine") + return; + + boost::shared_ptr aData = feature()->data(); + + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + anAttr->setFeature(theFeature); +} + +void PartSet_OperationConstraint::setValue(const double theValue) +{ + boost::shared_ptr aData = feature()->data(); + + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); + anAttr->setValue(theValue); + +} diff --git a/src/PartSet/PartSet_OperationConstraint.h b/src/PartSet/PartSet_OperationConstraint.h index fe1ea19ce..6fc31b709 100644 --- a/src/PartSet/PartSet_OperationConstraint.h +++ b/src/PartSet/PartSet_OperationConstraint.h @@ -20,7 +20,7 @@ class PARTSET_EXPORT PartSet_OperationConstraint : public PartSet_OperationSketc public: /// Returns the operation type key - static std::string Type() { return "SketchConstraintDistance"; } + static std::string Type() { return "SketchConstraintLength"; } public: /// Constructor @@ -85,6 +85,14 @@ protected: /// \returns the created feature virtual boost::shared_ptr createFeature(const bool theFlushMessage = true); + /// Set the feature for the constraint + /// \param theFeature the line feature + void setFeature(boost::shared_ptr theFeature); + + /// Set the value for the constraint + /// \param theValue the constraint value + void setValue(const double theValue); + private: boost::shared_ptr mySketch; ///< the sketch feature }; diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index ece04ed94..abdf6b3c1 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #ifdef _DEBUG @@ -32,9 +34,6 @@ using namespace std; -const Quantity_NameOfColor SKETCH_PLANE_COLOR = Quantity_NOC_CHOCOLATE; /// the plane edge color -const int SKETCH_WIDTH = 4; /// the plane edge width - PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) : PartSet_OperationSketchBase(theId, theParent) @@ -52,6 +51,7 @@ std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr +void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted) +{ + if (!hasSketchPlane()) { + } + else { + if (!theSelected.empty()) { + XGUI_ViewerPrs aPrs = theSelected.front(); + if (!aPrs.owner().IsNull()) { + Handle(AIS_DimensionOwner) anOwner = Handle(AIS_DimensionOwner)::DownCast(aPrs.owner()); + if (!anOwner.IsNull() && anOwner->SelectionMode() == AIS_DSM_Text) { + Handle(SelectMgr_SelectableObject) anObject = anOwner->Selectable(); + double aValue = 0; + if (!anObject.IsNull()) { + Handle(AIS_LengthDimension) aLenDim = Handle(AIS_LengthDimension)::DownCast(anObject); + if (!aLenDim.IsNull()) + aValue = aLenDim->GetValue(); + } + + QLineEdit* aLine = new QLineEdit(); + QPoint aViewPos = theEvent->globalPos(); + QPoint aLinePos(aViewPos.x(), aViewPos.y()); + aLine->move(aLinePos); + aLine->setText(QString::number(aValue)); + aLine->show(); + } + } + } + } +} + void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView) { if (!hasSketchPlane() || !(theEvent->buttons() & Qt::LeftButton) || myFeatures.empty()) @@ -146,17 +179,6 @@ bool PartSet_OperationSketch::isNestedOperationsEnabled() const return hasSketchPlane(); } -void PartSet_OperationSketch::correctPresentation(Handle(AIS_InteractiveObject) thePresentation) -{ - Handle(AIS_Shape) anAIS = Handle(AIS_Shape)::DownCast(thePresentation); - if (anAIS.IsNull()) - return; - - anAIS->SetColor(Quantity_Color(SKETCH_PLANE_COLOR)); - anAIS->SetWidth(SKETCH_WIDTH); - anAIS->Redisplay(); -} - void PartSet_OperationSketch::startOperation() { if (!feature()) { diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index f3b2e7731..dd117daf2 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -55,6 +55,15 @@ public: virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView, const std::list& theSelected, const std::list& theHighlighted); + /// Processes the mouse release in the point + /// \param theEvent the mouse event + /// \param theView a viewer to have the viewer the eye position + /// \param theSelected the list of selected presentations + /// \param theHighlighted the list of highlighted presentations + virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView, + const std::list& theSelected, + const std::list& theHighlighted); + /// Gives the current mouse point in the viewer /// \param thePoint a point clicked in the viewer /// \param theEvent the mouse event @@ -75,10 +84,6 @@ public: /// \return enabled state virtual bool isNestedOperationsEnabled() const; - /// Corrects the presentation settings by the operation - /// thePresentation an operation presentation - void correctPresentation(Handle_AIS_InteractiveObject thePresentation); - signals: /// signal about the sketch plane is selected /// \param theX the value in the X direction of the plane diff --git a/src/PartSet/PartSet_Presentation.cpp b/src/PartSet/PartSet_Presentation.cpp new file mode 100644 index 000000000..fa1b21f5f --- /dev/null +++ b/src/PartSet/PartSet_Presentation.cpp @@ -0,0 +1,149 @@ +// File: PartSet_Presentation.h +// Created: 02 June 2014 +// Author: Natalia ERMOLAEVA + +#include +#include + +#include +#include + +#include +#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( + boost::shared_ptr theFeature, + boost::shared_ptr theSketch, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs) +{ + Handle(AIS_InteractiveObject) anAIS; + + if (theFeature->getKind() == "SketchConstraintLength") + anAIS = createSketchConstraintLength(theFeature, theSketch, thePrevPrs); + else { + anAIS = createFeature(theFeature, theShape, thePrevPrs); + if (theFeature->getKind() == "Sketch") + { + 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( + boost::shared_ptr theFeature, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs) +{ + Handle(AIS_InteractiveObject) anAIS = thePrevPrs; + 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; +} + +Handle(AIS_InteractiveObject) PartSet_Presentation::createSketchConstraintLength( + boost::shared_ptr theFeature, + boost::shared_ptr theSketch, + Handle(AIS_InteractiveObject) thePrevPrs) +{ + if (!theFeature || !theSketch) + return thePrevPrs; + + boost::shared_ptr aData = theSketch->data(); + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aNormal = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_NORM)); + gp_Pln aPlane(aNormal->x(), aNormal->y(), aNormal->z(), 0/*D*/); + + aData = theFeature->data(); + boost::shared_ptr anAttr = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + if (!anAttr) + return thePrevPrs; + boost::shared_ptr aFeature = anAttr->feature(); + if (!aFeature || aFeature->getKind() != "SketchLine") + return thePrevPrs; + + aData = aFeature->data(); + if (!aData->isValid()) + return thePrevPrs; + + 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; + + Handle(AIS_InteractiveObject) anAIS = thePrevPrs; + if (anAIS.IsNull()) + { + Handle(AIS_LengthDimension) aLenDim = new AIS_LengthDimension (aP1, aP2, aPlane); + + Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect(); + anAspect->MakeArrows3d (Standard_False); + anAspect->MakeText3d(false/*is text 3d*/); + anAspect->TextAspect()->SetHeight(28); + anAspect->MakeTextShaded(false/*is test shaded*/); + aLenDim->DimensionAspect()->MakeUnitsDisplayed(false/*is units displayed*/); + /*if (isUnitsDisplayed) + { + aLenDim->SetDisplayUnits (aDimDlg->GetUnits ()); + }*/ + aLenDim->SetDimensionAspect (anAspect); + aLenDim->SetFlyout(12); + + anAIS = aLenDim; + } + else { + // update presentation + Handle(AIS_LengthDimension) aDimAIS = Handle(AIS_LengthDimension)::DownCast(anAIS); + if (!aDimAIS.IsNull()) { + aDimAIS->SetMeasuredGeometry(aPoint1, aPoint2, aPlane); + aDimAIS->Redisplay(Standard_True); + } + } + return anAIS; +} diff --git a/src/PartSet/PartSet_Presentation.h b/src/PartSet/PartSet_Presentation.h new file mode 100644 index 000000000..ffe8ed4db --- /dev/null +++ b/src/PartSet/PartSet_Presentation.h @@ -0,0 +1,44 @@ +// File: PartSet_Presentation.h +// Created: 02 Jun 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_Presentation_H +#define PartSet_Presentation_H + +#include "PartSet.h" + +#include + +#include + +class ModelAPI_Feature; +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 + /// \param theFeature a feature + /// \return the presentation + static Handle_AIS_InteractiveObject createPresentation( + boost::shared_ptr theFeature, + boost::shared_ptr theSketch, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs); +protected: + static Handle_AIS_InteractiveObject createFeature( + boost::shared_ptr theFeature, + const TopoDS_Shape& theShape, + Handle_AIS_InteractiveObject thePrevPrs); + + static Handle_AIS_InteractiveObject createSketchConstraintLength( + boost::shared_ptr theFeature, + boost::shared_ptr theSketch, + Handle_AIS_InteractiveObject thePrevPrs); +}; + +#endif diff --git a/src/PartSet/PartSet_TestOCC.cpp b/src/PartSet/PartSet_TestOCC.cpp index 60798a78b..59523f1cc 100644 --- a/src/PartSet/PartSet_TestOCC.cpp +++ b/src/PartSet/PartSet_TestOCC.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -146,7 +147,13 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) boost::shared_ptr aPreview = PartSet_OperationSketchLine::preview(aFeature); XGUI_Displayer* aDisplayer = theWorkshop->displayer(); - aDisplayer->Redisplay(aFeature, aPreview ? aPreview->impl() : TopoDS_Shape(), false); + + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aSketch, + aPreview ? aPreview->impl() : TopoDS_Shape(), NULL); + if (!anAIS.IsNull()) + aDisplayer->Redisplay(aFeature, anAIS, -1, false); + std::list aModes; aModes.push_back(TopAbs_VERTEX); aModes.push_back(TopAbs_EDGE); @@ -158,9 +165,13 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) aDelta = aDelta - i*2; PartSet_OperationSketchLine::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START); PartSet_OperationSketchLine::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END); - boost::shared_ptr aPreview = PartSet_OperationSketchLine::preview(aFeature); - theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl() : TopoDS_Shape(), true); + boost::shared_ptr aPreview = PartSet_OperationSketchLine::preview(aFeature); + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aSketch, + aPreview ? aPreview->impl() : TopoDS_Shape(), NULL); + if (!anAIS.IsNull()) + aDisplayer->Redisplay(aFeature, anAIS, -1, true); int aVal = 90; for (int j = 0; j < 10000000; j++) @@ -174,7 +185,7 @@ void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop) myTestFeature = aFeature; std::list aPrs; - aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape())); + aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape(), NULL)); aDisplayer->SetSelected(aPrs, true); } } @@ -192,7 +203,14 @@ void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop) PartSet_OperationSketchLine::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END); boost::shared_ptr aPreview = PartSet_OperationSketchLine::preview(aFeature); - theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl() : TopoDS_Shape(), true); + Handle(AIS_InteractiveObject) aPrevAIS; + boost::shared_ptr aSketch;//NULL + Handle(AIS_InteractiveObject) anAIS = PartSet_Presentation::createPresentation( + aFeature, aSketch, + aPreview ? aPreview->impl() : TopoDS_Shape(), + aPrevAIS); + if (!anAIS.IsNull()) + theWorkshop->displayer()->Redisplay(aFeature, anAIS, -1, true); //std::list aModes; //aModes.clear(); //aModes.push_back(TopAbs_VERTEX); diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 2c7a93b06..596c86756 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -103,6 +103,29 @@ void PartSet_Tools::ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptrx() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); } +void PartSet_Tools::ConvertTo3D(const double theX, const double theY, + boost::shared_ptr theSketch, + gp_Pnt& thePoint) +{ + if (!theSketch) + return; + + boost::shared_ptr aData = theSketch->data(); + + boost::shared_ptr aC = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + boost::shared_ptr aX = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::shared_ptr aY = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + + boost::shared_ptr aSum = aC->pnt()->xyz()->added( + aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY)); + + boost::shared_ptr aPoint = boost::shared_ptr(new GeomAPI_Pnt(aSum)); + thePoint = gp_Pnt(aPoint->x(), aPoint->y(), aPoint->z()); +} + void PartSet_Tools::IntersectLines(double theX0, double theY0, double theX1, double theY1, double theX2, double theY2, double theX3, double theY3, double& theX, double& theY) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 957585b26..116b58e82 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -39,6 +39,15 @@ public: static void ConvertTo2D(const gp_Pnt& thePoint, boost::shared_ptr theSketch, Handle(V3d_View) theView, double& theX, double& theY); + /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point. + /// \param theX the X coordinate + /// \param theY the Y coordinate + /// \param theSketch the sketch feature + /// \param thePoint the 3D point in the viewer + static void ConvertTo3D(const double theX, const double theY, + boost::shared_ptr theSketch, + gp_Pnt& thePoint); + /// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3), /// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line /// \param theX0 the horizontal coordinate of 0 point diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 9a4d7cf76..5c0f982e9 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -40,8 +40,12 @@ SET(PROJECT_LIBRARIES ModelAPI ) +SET(XML_RESOURCES + plugin-Sketch.xml +) + ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) -ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +ADD_LIBRARY(SketchPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES}) TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES}) INCLUDE_DIRECTORIES( @@ -51,9 +55,5 @@ INCLUDE_DIRECTORIES( ../GeomDataAPI ) -SET(XML_RESOURCES - plugin-Sketch.xml -) - INSTALL(TARGETS SketchPlugin DESTINATION plugins) INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index be9b3f879..be4bb9e41 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -1,7 +1,7 @@ - + @@ -19,8 +19,10 @@ - - + + + diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 2e8a1fae8..83bc31671 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -94,7 +94,7 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptrdata()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) ); if (!anAttr) continue; - if (anAttr->isFeature()) + if (anAttr->isFeature() && anAttr->feature()) { // verify posiible entities const std::string& aKind = anAttr->feature()->getKind(); if (aKind.compare("SketchPoint") == 0) @@ -149,7 +149,8 @@ const int& SketchSolver_Constraint::getType(boost::shared_ptrdata()->attribute(CONSTRAINT_ATTRIBUTES[indAttr]) ); if (!anAttr) continue; - if (anAttr->isFeature() && anAttr->feature()->getKind().compare("SketchLine") == 0) + if (anAttr->isFeature() && anAttr->feature() && + anAttr->feature()->getKind().compare("SketchLine") == 0) { myAttributesList[aNbLines++] = CONSTRAINT_ATTRIBUTES[indAttr]; break; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index dd763359d..3a2661e19 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -64,13 +65,15 @@ std::list XGUI_Displayer::GetSelected(const int theShapeTypeToSk for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); TopoDS_Shape aShape = aContext->SelectedShape(); + if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) continue; boost::shared_ptr aFeature = GetFeature(anIO); if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) continue; - aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape)); + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, anOwner)); aPrsFeatures.insert(aFeature); } return aPresentations; @@ -91,7 +94,7 @@ std::list XGUI_Displayer::GetHighlighted(const int theShapeTypeT boost::shared_ptr aFeature = GetFeature(anIO); if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) continue; - aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape)); + aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape, NULL)); aPrsFeatures.insert(aFeature); } @@ -118,7 +121,9 @@ void XGUI_Displayer::Erase(boost::shared_ptr theFeature, } bool XGUI_Displayer::Redisplay(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, const bool isUpdateViewer) + Handle(AIS_InteractiveObject) theAIS, + const int theSelectionMode, + const bool isUpdateViewer) { bool isCreated = false; Handle(AIS_InteractiveContext) aContext = AISContext(); @@ -131,24 +136,19 @@ bool XGUI_Displayer::Redisplay(boost::shared_ptr theFeature, //aContext->SetPixelTolerance(MOUSE_SENSITIVITY_IN_PIXEL); } // display or redisplay presentation - Handle(AIS_Shape) anAIS; - if (IsVisible(theFeature)) { - anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]); - if (!anAIS.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. - anAIS->Set(theShape); - anAIS->Redisplay(Standard_True); - aContext->RecomputeSelectionOnly(anAIS); - } + if (IsVisible(theFeature) && !myFeature2AISObjectMap[theFeature].IsNull()) { + aContext->RecomputeSelectionOnly(theAIS); } else { - anAIS = new AIS_Shape(theShape); - myFeature2AISObjectMap[theFeature] = anAIS; - aContext->Display(anAIS, false); + myFeature2AISObjectMap[theFeature] = theAIS; + if (theSelectionMode < 0) + { + aContext->Display(theAIS, false); + } + else + { + aContext->Display(theAIS, 0, theSelectionMode, false); + } isCreated = true; } if (isUpdateViewer) diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index dd3ccb4dc..f9ff755ca 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -70,12 +70,17 @@ public: /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance - /// \param theShape a shape - /// \param theMode a local selection mode + /// \param theAIS an AIS object /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly /// \returns true if the presentation is created bool Redisplay(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape, const bool isUpdateViewer = true); + Handle(AIS_InteractiveObject) theAIS, + const int theSelectionMode, const bool isUpdateViewer = true); + + /// Redisplay the shape and activate selection of sub-shapes + /// \param theFeature a feature instance + /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + //void Redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true); /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance diff --git a/src/XGUI/XGUI_ViewerPrs.cpp b/src/XGUI/XGUI_ViewerPrs.cpp index 4ab8801aa..50cc05d88 100644 --- a/src/XGUI/XGUI_ViewerPrs.cpp +++ b/src/XGUI/XGUI_ViewerPrs.cpp @@ -4,13 +4,16 @@ #include "XGUI_ViewerPrs.h" +#include "SelectMgr_EntityOwner.hxx" + XGUI_ViewerPrs::XGUI_ViewerPrs() { } XGUI_ViewerPrs::XGUI_ViewerPrs(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape) -: myFeature(theFeature), myShape(theShape) + const TopoDS_Shape& theShape, + Handle(SelectMgr_EntityOwner) theOwner) +: myFeature(theFeature), myShape(theShape), myOwner(theOwner) { } @@ -23,14 +26,24 @@ void XGUI_ViewerPrs::setFeature(boost::shared_ptr theFeature) myFeature = theFeature; } -void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape) +boost::shared_ptr XGUI_ViewerPrs::feature() const { - myShape = theShape; + return myFeature; } -boost::shared_ptr XGUI_ViewerPrs::feature() const +void XGUI_ViewerPrs::setOwner(Handle(SelectMgr_EntityOwner) theOwner) { - return myFeature; + myOwner = theOwner; +} + +Handle(SelectMgr_EntityOwner) XGUI_ViewerPrs::owner() const +{ + return myOwner; +} + +void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape) +{ + myShape = theShape; } const TopoDS_Shape& XGUI_ViewerPrs::shape() const diff --git a/src/XGUI/XGUI_ViewerPrs.h b/src/XGUI/XGUI_ViewerPrs.h index 957e4dc7c..b0e046b4e 100644 --- a/src/XGUI/XGUI_ViewerPrs.h +++ b/src/XGUI/XGUI_ViewerPrs.h @@ -9,12 +9,13 @@ #include #include +#include class ModelAPI_Feature; /**\class XGUI_ViewerPrs * \ingroup GUI - * \brief Presentation. Provides container to have feature and the shape + * \brief Presentation. Provides container to have feature, shape and/or selection owner. */ class XGUI_EXPORT XGUI_ViewerPrs { @@ -22,8 +23,12 @@ public: /// Constructor XGUI_ViewerPrs(); /// Constructor + /// \param theFeature a model feature + /// \param theShape a viewer shape + /// \param theOwner a selection owner XGUI_ViewerPrs(boost::shared_ptr theFeature, - const TopoDS_Shape& theShape); + const TopoDS_Shape& theShape, + Handle_SelectMgr_EntityOwner theOwner); /// Destructor virtual ~XGUI_ViewerPrs(); @@ -31,20 +36,29 @@ public: /// \param theFeature a feature instance void setFeature(boost::shared_ptr theFeature); - /// Sets the shape - /// \param theShape a shape instance - void setShape(const TopoDS_Shape& theShape); - /// Returns the feature. /// \return a feature instance boost::shared_ptr feature() const; + /// Returns the presentation owner + /// \param the owner + void setOwner(Handle_SelectMgr_EntityOwner theOwner); + + /// Returns the presentation owner + /// \return an owner + Handle_SelectMgr_EntityOwner owner() const; + + /// Sets the shape + /// \param theShape a shape instance + void setShape(const TopoDS_Shape& theShape); + /// Returns the shape /// \return a shape instance const TopoDS_Shape& shape() const; private: boost::shared_ptr myFeature; /// the feature + Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner TopoDS_Shape myShape; /// the shape }; -- 2.39.2