From: vsv Date: Fri, 12 Dec 2014 13:48:43 +0000 (+0300) Subject: Axis feature in Construction plugin is created X-Git-Tag: before_slalome_7.5.1~19^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a3cd8f27f76183cfc2d0728e6388696ab9dce1b8;p=modules%2Fshaper.git Axis feature in Construction plugin is created --- diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index b95bcb728..0ddbb7f1b 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -7,16 +7,19 @@ SET(PROJECT_HEADERS ConstructionPlugin.h ConstructionPlugin_Plugin.h ConstructionPlugin_Point.h + ConstructionPlugin_Axis.h ) SET(PROJECT_SOURCES ConstructionPlugin_Plugin.cpp ConstructionPlugin_Point.cpp + ConstructionPlugin_Axis.cpp ) SET(XML_RESOURCES plugin-Construction.xml point_widget.xml + axis_widget.xml ) SET(PROJECT_LIBRARIES diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp new file mode 100644 index 000000000..de672a25b --- /dev/null +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -0,0 +1,59 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ConstructionPlugin_Axis.cpp +// Created: 12 Dec 2014 +// Author: Vitaly Smetannikov + +#include "ConstructionPlugin_Axis.h" + +#include +#include + +#include +#include +#include + +using namespace std; + +static const double MINIMAL_LENGTH = 1.e-5; + +ConstructionPlugin_Axis::ConstructionPlugin_Axis() +{ +} + +void ConstructionPlugin_Axis::initAttributes() +{ + data()->addAttribute(POINT_ATTR_FIRST, ModelAPI_AttributeReference::type()); + data()->addAttribute(POINT_ATTR_SECOND, ModelAPI_AttributeReference::type()); +} + +void ConstructionPlugin_Axis::execute() +{ + AttributeReferencePtr aRef1 = data()->reference(POINT_ATTR_FIRST); + AttributeReferencePtr aRef2 = data()->reference(POINT_ATTR_SECOND); + if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) { + ResultConstructionPtr aPntObj1 = std::dynamic_pointer_cast(aRef1->value()); + ResultConstructionPtr aPntObj2 = std::dynamic_pointer_cast(aRef2->value()); + if ((aPntObj1.get() != NULL) && (aPntObj2.get() != NULL)) { + GeomShapePtr aShape1 = aPntObj1->shape(); + GeomShapePtr aShape2 = aPntObj2->shape(); + if (aShape1->isVertex() && aShape2->isVertex()) { + std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); + std::shared_ptr anEnd = GeomAlgoAPI_PointBuilder::point(aShape2); + if (aStart->distance(anEnd) > MINIMAL_LENGTH) { + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, anEnd); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setShape(anEdge); + setResult(aConstr); + } + } + } + } +} + +void ConstructionPlugin_Axis::customisePresentation(AISObjectPtr thePrs) +{ + thePrs->setColor(0, 0, 0); + thePrs->setLineStyle(3); +} \ No newline at end of file diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h new file mode 100644 index 000000000..099d547e3 --- /dev/null +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -0,0 +1,55 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ConstructionPlugin_Axis.h +// Created: 12 Dec 2014 +// Author: Vitaly Smetannikov + +#ifndef ConstructionPlugin_Axis_H +#define ConstructionPlugin_Axis_H + +#include "ConstructionPlugin.h" +#include +#include + + +/// Point kind +const std::string CONSTRUCTION_AXIS_KIND("Axis"); + +/// attribute name for first point +const std::string POINT_ATTR_FIRST = "firstPoint"; + +/// attribute name for second point +const std::string POINT_ATTR_SECOND = "secondPoint"; + +/**\class ConstructionPlugin_Axis + * \ingroup DataModel + * \brief Feature for creation of the new axis in PartSet. + */ +class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomPrs +{ + public: + /// Returns the kind of a feature + CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = CONSTRUCTION_AXIS_KIND; + return MY_KIND; + } + + /// Creates a new part document if needed + CONSTRUCTIONPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes(); + + /// Construction result is allways recomuted on the fly + CONSTRUCTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} + + /// Use plugin manager for features creation + ConstructionPlugin_Axis(); + + /// Customize presentation of the feature + virtual void customisePresentation(AISObjectPtr thePrs); +}; + + +#endif \ No newline at end of file diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 008d13952..bd7465df5 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -2,6 +2,7 @@ #include "ConstructionPlugin_Plugin.h" #include "ConstructionPlugin_Point.h" +#include "ConstructionPlugin_Axis.h" #include #include @@ -22,6 +23,9 @@ FeaturePtr ConstructionPlugin_Plugin::createFeature(string theFeatureID) if (theFeatureID == CONSTRUCTION_POINT_KIND) { return FeaturePtr(new ConstructionPlugin_Point); } + else if (theFeatureID == CONSTRUCTION_AXIS_KIND) { + return FeaturePtr(new ConstructionPlugin_Axis); + } // feature of such kind is not found return FeaturePtr(); } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index 56e921ab5..637b96193 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -34,13 +34,6 @@ class ConstructionPlugin_Point : public ModelAPI_Feature return MY_KIND; } - /// Returns to which group in the document must be added feature - CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup() - { - static std::string MY_GROUP = "Construction"; - return MY_GROUP; - } - /// Creates a new part document if needed CONSTRUCTIONPLUGIN_EXPORT virtual void execute(); diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml new file mode 100644 index 000000000..e6472b6db --- /dev/null +++ b/src/ConstructionPlugin/axis_widget.xml @@ -0,0 +1,17 @@ + + + + + + + + diff --git a/src/ConstructionPlugin/plugin-Construction.xml b/src/ConstructionPlugin/plugin-Construction.xml index d7d623536..2d670f963 100644 --- a/src/ConstructionPlugin/plugin-Construction.xml +++ b/src/ConstructionPlugin/plugin-Construction.xml @@ -14,9 +14,9 @@ id="Axis" title="Axis" tooltip="Create a new axis" - icon=":icons/axis.png" - keysequence="" - internal="true" /> + icon=":icons/axis.png"> + + (); + if (!anAIS.IsNull()) { + Handle(AIS_Drawer) aDrawer = anAIS->Attributes(); + if (aDrawer->HasLineAspect()) + aDrawer->LineAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle); + if (aDrawer->HasWireAspect()) + aDrawer->WireAspect()->SetTypeOfLine((Aspect_TypeOfLine)theStyle); + //else { + // Quantity_NameOfColor aCol = Quantity_NOC_RED; + // aDrawer->SetLineAspect(new Prs3d_LineAspect(aCol, (Aspect_TypeOfLine)theStyle, 1)); + //} + } +} diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index 1477c5a13..ce2d7e0d4 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -103,6 +103,10 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface /// Sets marker type for vertex. /// The type has to be defined according to Acpect_TypeOfMarker void setPointMarker(int theType, double theScale); + + /// Set line type of edges + /// Has to be defined according to Aspect_TypeOfLine + void setLineStyle(int theStyle); }; //! Pointer on attribute object diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp index 2ff0726bf..f57605c8c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -8,7 +8,10 @@ #include #include #include +#include #include +#include +#include std::shared_ptr GeomAlgoAPI_PointBuilder::point( std::shared_ptr thePoint) @@ -20,3 +23,16 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::point( aRes->setImpl(new TopoDS_Shape(aVertex)); return aRes; } + + +std::shared_ptr GeomAlgoAPI_PointBuilder::point(std::shared_ptr theVertex) +{ + TopoDS_Shape aShape = theVertex->impl(); + if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) { + TopoDS_Vertex aVertex = TopoDS::Vertex(aShape); + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + std::shared_ptr aPnt(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())); + return aPnt; + } + return std::shared_ptr(); +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h index 64e479ce1..893c70c97 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h @@ -21,8 +21,11 @@ class GeomAPI_Pnt; class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder { public: - /// Creates linear edge by two points + /// Creates a shape by point static std::shared_ptr point(std::shared_ptr thePoint); + + /// Return point by shape vertex + static std::shared_ptr point(std::shared_ptr theVertex); }; #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 388419ad7..b13d3542e 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -542,7 +542,7 @@ void PartSet_Module::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* t void PartSet_Module::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); - if (aOperation->isEditOperation()) { + if (aOperation && aOperation->isEditOperation()) { std::string aId = aOperation->id().toStdString(); if ((aId == SketchPlugin_ConstraintLength::ID()) || (aId == SketchPlugin_ConstraintDistance::ID()) || diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 3a530c2f4..3e6314a96 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -59,13 +59,13 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer) GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); bool isShading = false; - if (aPrs) { + if (aPrs.get() != NULL) { anAIS = aPrs->getAISObject(AISObjectPtr()); } else { ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult) { + if (aResult.get() != NULL) { std::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); - if (aShapePtr) { + if (aShapePtr.get() != NULL) { anAIS = AISObjectPtr(new GeomAPI_AISObject()); anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult))); //anAIS->createShape(aShapePtr);