From f2337211db0c2b449dd065dd195ffe76d5fd7116 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 26 Apr 2016 11:47:08 +0300 Subject: [PATCH] Issue #1114: Provide selection of origin and axis of trihedron with reference to corresponded model objects --- .../ConstructionPlugin_Axis.cpp | 44 ++++++++++++++ .../ConstructionPlugin_Axis.h | 23 ++++++++ src/GeomAPI/GeomAPI_Vertex.cpp | 9 +++ src/GeomAPI/GeomAPI_Vertex.h | 6 +- .../InitializationPlugin_Plugin.cpp | 46 +++++++++++++-- .../InitializationPlugin_Plugin.h | 16 ++++- .../ParametersPlugin_WidgetParamsMgr.cpp | 32 ++++++++-- .../ParametersPlugin_WidgetParamsMgr.h | 2 + src/XGUI/XGUI_Selection.cpp | 59 ++++++++++++------- 9 files changed, 204 insertions(+), 33 deletions(-) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 8a6c2a5d0..20a11909a 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -11,8 +11,10 @@ #include #include #include +#include #include +#include #include #include @@ -36,6 +38,12 @@ void ConstructionPlugin_Axis::initAttributes() ModelAPI_AttributeSelection::typeId()); data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::X_DIRECTION(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::Y_DIRECTION(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ConstructionPlugin_Axis::Z_DIRECTION(), + ModelAPI_AttributeDouble::typeId()); } void ConstructionPlugin_Axis::createAxisByTwoPoints() @@ -64,6 +72,38 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints() } } + +void ConstructionPlugin_Axis::createAxisByPointAndDirection() +{ + AttributeSelectionPtr aRef1 = data()->selection(ConstructionPlugin_Axis::POINT_FIRST()); + AttributeDoublePtr aXAttr = data()->real(ConstructionPlugin_Axis::X_DIRECTION()); + AttributeDoublePtr aYAttr = data()->real(ConstructionPlugin_Axis::Y_DIRECTION()); + AttributeDoublePtr aZAttr = data()->real(ConstructionPlugin_Axis::Z_DIRECTION()); + if ((aRef1.get() != NULL) && (aXAttr.get() != NULL) && + (aYAttr.get() != NULL) && (aZAttr.get() != NULL)) { + GeomShapePtr aShape1 = aRef1->value(); + if (!aShape1.get()) + aShape1 = aRef1->context()->shape(); + + std::shared_ptr aVertex(new GeomAPI_Vertex(aXAttr->value(), + aYAttr->value(), + aZAttr->value())); + if (aShape1->isVertex() && (!aShape1->isEqual(aVertex))) { + std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); + std::shared_ptr anEnd = GeomAlgoAPI_PointBuilder::point(aVertex); + if (aStart->distance(anEnd) > ConstructionPlugin_Axis::MINIMAL_LENGTH()) { + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); + aConstr->setShape(anEdge); + setResult(aConstr); + } + } + } +} + + void ConstructionPlugin_Axis::createAxisByCylindricalFace() { std::shared_ptr aSelection = data()->selection(CYLINDRICAL_FACE())->value(); @@ -78,6 +118,8 @@ void ConstructionPlugin_Axis::createAxisByCylindricalFace() } } + + void ConstructionPlugin_Axis::execute() { AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); @@ -86,6 +128,8 @@ void ConstructionPlugin_Axis::execute() createAxisByTwoPoints(); } else if (aMethodType == "AxisByCylindricalFaceCase") { createAxisByCylindricalFace(); + } else if (aMethodType == "AxisByPointAndDirection") { + createAxisByPointAndDirection(); } } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index ffaa95d04..4c51a1d40 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -58,6 +58,27 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP return CYLINDRICAL_FACE_ATTR; } + /// attribute name for X direction + inline static const std::string& X_DIRECTION() + { + static const std::string ATTR_X_DIRECTION("X_Direction"); + return ATTR_X_DIRECTION; + } + + /// attribute name for Y direction + inline static const std::string& Y_DIRECTION() + { + static const std::string ATTR_Y_DIRECTION("Y_Direction"); + return ATTR_Y_DIRECTION; + } + + /// attribute name for Y direction + inline static const std::string& Z_DIRECTION() + { + static const std::string ATTR_Z_DIRECTION("Z_Direction"); + return ATTR_Z_DIRECTION; + } + /// Returns a minimal length for axis inline static const double MINIMAL_LENGTH() { return 1.e-5; } @@ -82,6 +103,8 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP void createAxisByTwoPoints(); /// Creates a new axis as copy of cylindrical face axis void createAxisByCylindricalFace(); + /// Creates a new axis by point and direction + void createAxisByPointAndDirection(); }; diff --git a/src/GeomAPI/GeomAPI_Vertex.cpp b/src/GeomAPI/GeomAPI_Vertex.cpp index b917837a0..27060572c 100644 --- a/src/GeomAPI/GeomAPI_Vertex.cpp +++ b/src/GeomAPI/GeomAPI_Vertex.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,14 @@ GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr& theShape) } } +GeomAPI_Vertex::GeomAPI_Vertex(double theX, double theY, double theZ) +{ + TopoDS_Vertex aVertex; + BRep_Builder aBuilder; + aBuilder.MakeVertex(aVertex, gp_Pnt(theX, theY, theZ), Precision::Confusion()); + setImpl(new TopoDS_Shape(aVertex)); +} + std::shared_ptr GeomAPI_Vertex::point() { const TopoDS_Shape& aShape = const_cast(this)->impl(); diff --git a/src/GeomAPI/GeomAPI_Vertex.h b/src/GeomAPI/GeomAPI_Vertex.h index 9baf0dcdc..c1ec7109c 100644 --- a/src/GeomAPI/GeomAPI_Vertex.h +++ b/src/GeomAPI/GeomAPI_Vertex.h @@ -23,10 +23,14 @@ public: GEOMAPI_EXPORT GeomAPI_Vertex(); - /// Creation of edge by the edge-shape + /// Creation of vertex by the vertex-shape GEOMAPI_EXPORT GeomAPI_Vertex(const std::shared_ptr& theShape); + /// Creation of vertex by 3d coordinates + GEOMAPI_EXPORT + GeomAPI_Vertex(double theX, double theY, double theZ); + /// Returns the first vertex coordinates of the edge GEOMAPI_EXPORT std::shared_ptr point(); diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp index 7418469e6..b896d594b 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.cpp +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -46,7 +47,11 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptrsend(aMsg); - aFeatures.push_back(createPoint(aDoc)); + FeaturePtr aOrigin = createPoint(aDoc, "Origin", 0., 0., 0.); + aFeatures.push_back(aOrigin); + aFeatures.push_back(createAxis(aDoc, aOrigin, 100., 0., 0.)); + aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 100., 0.)); + aFeatures.push_back(createAxis(aDoc, aOrigin, 0., 0., 100.)); aFeatures.push_back(createPlane(aDoc, 1., 0., 0.)); aFeatures.push_back(createPlane(aDoc, 0., -1., 0.)); aFeatures.push_back(createPlane(aDoc, 0., 0., 1.)); @@ -110,13 +115,14 @@ FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double t return aPlane; } -FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc) +FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc, const std::string& theName, + double theX, double theY, double theZ) { std::shared_ptr aPoint = theDoc->addFeature("Point"); - aPoint->real("x")->setValue(0.); - aPoint->real("y")->setValue(0.); - aPoint->real("z")->setValue(0.); - aPoint->data()->setName("Origin"); + aPoint->real("x")->setValue(theX); + aPoint->real("y")->setValue(theY); + aPoint->real("z")->setValue(theZ); + aPoint->data()->setName(theName); aPoint->setInHistory(aPoint, false); // don't show automatically created feature in the features history // the point should be executed in order to build the feature result immediatelly @@ -127,3 +133,31 @@ FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc) return aPoint; } + +FeaturePtr InitializationPlugin_Plugin::createAxis(DocumentPtr theDoc, FeaturePtr theOrigin, + double theX, double theY, double theZ) +{ + std::shared_ptr aAxis = theDoc->addFeature("Axis"); + aAxis->string("CreationMethod")->setValue("AxisByPointAndDirection"); + + ResultPtr aResult = theOrigin->firstResult(); + aAxis->selection("FirstPoint")->setValue(aResult, aResult->shape()); + + aAxis->real("X_Direction")->setValue(theX); + aAxis->real("Y_Direction")->setValue(theY); + aAxis->real("Z_Direction")->setValue(theZ); + + if (theX != 0) { + aAxis->data()->setName("OX"); + } else if (theY != 0) { + aAxis->data()->setName("OY"); + } else if (theZ != 0) { + aAxis->data()->setName("OZ"); + } + aAxis->setInHistory(aAxis, false); // don't show automatically created feature in the features history + aAxis->execute(); + aAxis->data()->execState(ModelAPI_StateDone); + aAxis->firstResult()->data()->execState(ModelAPI_StateDone); + + return aAxis; +} diff --git a/src/InitializationPlugin/InitializationPlugin_Plugin.h b/src/InitializationPlugin/InitializationPlugin_Plugin.h index 42d157703..c44c7a43f 100644 --- a/src/InitializationPlugin/InitializationPlugin_Plugin.h +++ b/src/InitializationPlugin/InitializationPlugin_Plugin.h @@ -35,7 +35,21 @@ class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_Plugin : public Events_Li FeaturePtr createPlane(DocumentPtr theDoc, double theX, double theY, double theZ); /// Creates the origin point in (0,0,0) /// \param theDoc - document to contain a "point" feature - FeaturePtr createPoint(DocumentPtr theDoc); + /// \param theName - name of the point + /// \param theX - X coordinate + /// \param theY - Y coordinate + /// \param theZ - Z coordinate + FeaturePtr createPoint(DocumentPtr theDoc, const std::string& theName, + double theX, double theY, double theZ); + + /// Creates an axis which is started from origin point + /// \param theDoc - document to contain an "axis" feature + /// \param theOrigin - origin point feature + /// \param theX - X of direction point + /// \param theY - Y of direction point + /// \param theZ - Z of direction point + FeaturePtr createAxis(DocumentPtr theDoc, FeaturePtr theOrigin, + double theX, double theY, double theZ); }; #endif diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index 676133128..a0d88f734 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -215,6 +215,17 @@ bool ParametersPlugin_WidgetParamsMgr::restoreValueCustom() void ParametersPlugin_WidgetParamsMgr::activateCustom() { + updateParametersFeatures(); + updateParametersPart(); + updateFeaturesPart(); + + myFeatures->setExpanded(true); + myParameters->setExpanded(true); +} + +void ParametersPlugin_WidgetParamsMgr::updateParametersFeatures() +{ + myParametersList.clear(); FeaturePtr aFeature = feature(); DocumentPtr aDoc = aFeature->document(); int aNbParam = aDoc->size(ModelAPI_ResultParameter::group()); @@ -227,11 +238,6 @@ void ParametersPlugin_WidgetParamsMgr::activateCustom() myParametersList.append(aParamFeature); } } - updateParametersPart(); - updateFeaturesPart(); - - myFeatures->setExpanded(true); - myParameters->setExpanded(true); } void ParametersPlugin_WidgetParamsMgr::updateFeaturesPart() @@ -530,7 +536,9 @@ void ParametersPlugin_WidgetParamsMgr::onRemove() Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)); Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + updateParametersFeatures(); updateFeaturesPart(); + updateParametersPart(); } } @@ -567,6 +575,13 @@ void ParametersPlugin_WidgetParamsMgr::onUp() myParameters->insertChild(aCurrentPos - 1, aCurrentItem); selectItemScroll(aCurrentItem); + + //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)); + //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)); + //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + //updateParametersFeatures(); + //updateParametersPart(); + //updateFeaturesPart(); } void ParametersPlugin_WidgetParamsMgr::onDown() @@ -591,6 +606,13 @@ void ParametersPlugin_WidgetParamsMgr::onDown() myParameters->insertChild(aCurrentPos + 1, aCurrentItem); selectItemScroll(aCurrentItem); + + //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)); + //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)); + //Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + //updateParametersFeatures(); + //updateParametersPart(); + //updateFeaturesPart(); } diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h index eb3903e03..91c772da0 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.h @@ -103,6 +103,8 @@ private: QList featuresItems(const QList& theFeatures) const; QList parametersItems(const QList& theFeatures) const; + void updateParametersFeatures(); + QTreeWidget* myTable; QTreeWidgetItem* myFeatures; QTreeWidgetItem* myParameters; diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index 6091e71f4..eb59cf8c8 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -15,6 +15,8 @@ #include #include +#include +#include #include #include @@ -146,32 +148,49 @@ void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrsPtr& thePrs, #ifdef DEBUG_DELIVERY // Fill by trihedron shapes Handle(AIS_Axis) aAxis = Handle(AIS_Axis)::DownCast(anIO); + DocumentPtr aDoc = ModelAPI_Session::get()->moduleDocument(); + int aSize = aDoc->size(ModelAPI_ResultConstruction::group()); + ObjectPtr aObj; if (!aAxis.IsNull()) { // an Axis from Trihedron - Handle(Geom_Line) aLine = aAxis->Component(); - Handle(Prs3d_DatumAspect) DA = aAxis->Attributes()->DatumAspect(); - Handle(Geom_TrimmedCurve) aTLine = new Geom_TrimmedCurve(aLine, 0, DA->FirstAxisLength()); - - BRep_Builder aBuilder; - TopoDS_Edge aEdge; - aBuilder.MakeEdge(aEdge, aTLine, Precision::Confusion()); - if (!aEdge.IsNull()) { - std::shared_ptr aGeomShape = std::shared_ptr(new GeomAPI_Shape()); - aGeomShape->setImpl(new TopoDS_Shape(aEdge)); - thePrs->setShape(aGeomShape); + gp_Lin aLine = aAxis->Component()->Lin(); + gp_Dir aDir = aLine.Direction(); + std::string aAxName; + if (aDir.X() == 1.) + aAxName = "OX"; + else if (aDir.Y() == 1.) + aAxName = "OY"; + else if (aDir.Z() == 1.) + aAxName = "OZ"; + if (aAxName.length() > 0) { + ResultPtr aAx; + for (int i = 0; i < aSize; i++) { + aObj = aDoc->object(ModelAPI_ResultConstruction::group(), i); + if (aObj->data()->name() == aAxName) { + aAx = std::dynamic_pointer_cast(aObj); + break; + } + } + if (aAx.get()) { + thePrs->setObject(aAx); + thePrs->setShape(aAx->shape()); + } } } else { Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast(anIO); if (!aPoint.IsNull()) { - // A point from trihedron - Handle(Geom_Point) aPnt = aPoint->Component(); - BRep_Builder aBuilder; - TopoDS_Vertex aVertex; - aBuilder.MakeVertex(aVertex, aPnt->Pnt(), Precision::Confusion()); - if (!aVertex.IsNull()) { - std::shared_ptr aGeomShape = std::shared_ptr(new GeomAPI_Shape()); - aGeomShape->setImpl(new TopoDS_Shape(aVertex)); - thePrs->setShape(aGeomShape); + // An origin point from trihedron + ResultPtr aOrigin; + for (int i = 0; i < aSize; i++) { + aObj = aDoc->object(ModelAPI_ResultConstruction::group(), i); + if (aObj->data()->name() == "Origin") { + aOrigin = std::dynamic_pointer_cast(aObj); + break; + } + } + if (aOrigin.get()) { + thePrs->setObject(aOrigin); + thePrs->setShape(aOrigin->shape()); } } } -- 2.30.2