From: vsv Date: Fri, 12 Dec 2014 16:29:54 +0000 (+0300) Subject: Plane object is added to construction plug-in X-Git-Tag: before_slalome_7.5.1~19^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=abcdb8af07666bf4ac9411fb73b19f395ee274bd;p=modules%2Fshaper.git Plane object is added to construction plug-in --- diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 0ddbb7f1b..0a1847283 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -8,18 +8,21 @@ SET(PROJECT_HEADERS ConstructionPlugin_Plugin.h ConstructionPlugin_Point.h ConstructionPlugin_Axis.h + ConstructionPlugin_Plane.h ) SET(PROJECT_SOURCES ConstructionPlugin_Plugin.cpp ConstructionPlugin_Point.cpp ConstructionPlugin_Axis.cpp + ConstructionPlugin_Plane.cpp ) SET(XML_RESOURCES plugin-Construction.xml point_widget.xml axis_widget.xml + plane_widget.xml ) SET(PROJECT_LIBRARIES diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index de672a25b..69b31a9f0 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -15,7 +15,7 @@ using namespace std; -static const double MINIMAL_LENGTH = 1.e-5; +static const double MINIMAL_LENGTH = 1.e-5; ConstructionPlugin_Axis::ConstructionPlugin_Axis() { diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp new file mode 100644 index 000000000..37faed970 --- /dev/null +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -0,0 +1,55 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ConstructionPlugin_Plane.cpp +// Created: 12 Dec 2014 +// Author: Vitaly Smetannikov + +#include "ConstructionPlugin_Plane.h" + +#include +#include +#include +#include + + +#define PLANE_SIZE 300 + +ConstructionPlugin_Plane::ConstructionPlugin_Plane() +{ +} + +void ConstructionPlugin_Plane::initAttributes() +{ + data()->addAttribute(FACE_ATTR, ModelAPI_AttributeSelection::type()); + data()->addAttribute(DISTANCE_ATTR, ModelAPI_AttributeDouble::type()); +} + +void ConstructionPlugin_Plane::execute() +{ + AttributeSelectionPtr aFaceAttr = data()->selection(FACE_ATTR); + AttributeDoublePtr aDistAttr = data()->real(DISTANCE_ATTR); + if ((aFaceAttr.get() != NULL) && (aDistAttr.get() != NULL) && + aFaceAttr->isInitialized() && aDistAttr->isInitialized()) { + + double aDist = aDistAttr->value(); + GeomShapePtr aShape = aFaceAttr->value(); + if (aShape.get() != NULL) { + std::shared_ptr aPln = GeomAlgoAPI_FaceBuilder::plane(aShape); + std::shared_ptr aOrig = aPln->location(); + std::shared_ptr aDir = aPln->direction(); + + aOrig->translate(aDir, aDist); + std::shared_ptr aPlane = + GeomAlgoAPI_FaceBuilder::square(aOrig, aDir, PLANE_SIZE); + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setShape(aPlane); + setResult(aConstr); + } + } +} + +void ConstructionPlugin_Plane::customisePresentation(AISObjectPtr thePrs) +{ + thePrs->setColor(50, 255, 50); + thePrs->setTransparensy(0.6); +} \ No newline at end of file diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.h b/src/ConstructionPlugin/ConstructionPlugin_Plane.h new file mode 100644 index 000000000..e58dd2ec4 --- /dev/null +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.h @@ -0,0 +1,53 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ConstructionPlugin_Plane.h +// Created: 12 Dec 2014 +// Author: Vitaly Smetannikov + +#ifndef ConstructionPlugin_Plane_H +#define ConstructionPlugin_Plane_H + +#include "ConstructionPlugin.h" +#include +#include + +/// Point kind +const std::string CONSTRUCTION_PLANE_KIND("Plane"); + +/// attribute name for base face +const std::string FACE_ATTR = "planeFace"; + +/// attribute name for distance +const std::string DISTANCE_ATTR = "distance"; + +/**\class ConstructionPlugin_Axis + * \ingroup DataModel + * \brief Feature for creation of the new axis in PartSet. + */ +class ConstructionPlugin_Plane : 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_PLANE_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_Plane(); + + /// 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 bd7465df5..4ce70ae03 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -3,6 +3,7 @@ #include "ConstructionPlugin_Plugin.h" #include "ConstructionPlugin_Point.h" #include "ConstructionPlugin_Axis.h" +#include "ConstructionPlugin_Plane.h" #include #include @@ -26,6 +27,9 @@ FeaturePtr ConstructionPlugin_Plugin::createFeature(string theFeatureID) else if (theFeatureID == CONSTRUCTION_AXIS_KIND) { return FeaturePtr(new ConstructionPlugin_Axis); } + else if (theFeatureID == CONSTRUCTION_PLANE_KIND) { + return FeaturePtr(new ConstructionPlugin_Plane); + } // feature of such kind is not found return FeaturePtr(); } diff --git a/src/ConstructionPlugin/plane_widget.xml b/src/ConstructionPlugin/plane_widget.xml new file mode 100644 index 000000000..bf062da02 --- /dev/null +++ b/src/ConstructionPlugin/plane_widget.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/src/ConstructionPlugin/plugin-Construction.xml b/src/ConstructionPlugin/plugin-Construction.xml index 2d670f963..68a3e4e7c 100644 --- a/src/ConstructionPlugin/plugin-Construction.xml +++ b/src/ConstructionPlugin/plugin-Construction.xml @@ -21,9 +21,9 @@ id="Plane" title="Plane" tooltip="Create a new plane" - icon=":icons/plane.png" - keysequence="" - internal="true" /> + icon=":icons/plane.png"> + + - \ No newline at end of file + diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 24e07eb08..a2b39e452 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -336,9 +337,16 @@ void GeomAPI_AISObject::setLineStyle(int theStyle) 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)); - //} + } +} + + +void GeomAPI_AISObject::setTransparensy(double theVal) +{ + Handle(AIS_InteractiveObject) anAIS = impl(); + if (!anAIS.IsNull()) { + Handle(AIS_InteractiveContext) aContext = anAIS->GetContext(); + if (!aContext.IsNull()) + aContext->SetTransparency(anAIS, theVal, false); } } diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index ce2d7e0d4..a76016bd6 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -107,6 +107,9 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface /// Set line type of edges /// Has to be defined according to Aspect_TypeOfLine void setLineStyle(int theStyle); + + /// Set transparency of the presentation (theVal = 0 ... 1) + void setTransparensy(double theVal); }; //! Pointer on attribute object diff --git a/src/GeomAPI/GeomAPI_Pnt.cpp b/src/GeomAPI/GeomAPI_Pnt.cpp index b4ad65976..d9bc12b6f 100644 --- a/src/GeomAPI/GeomAPI_Pnt.cpp +++ b/src/GeomAPI/GeomAPI_Pnt.cpp @@ -73,3 +73,12 @@ std::shared_ptr GeomAPI_Pnt::to2D(const std::shared_ptrx() + aVec.Y() * theDirY->y() + aVec.Z() * theDirY->z(); return std::shared_ptr(new GeomAPI_Pnt2d(aX, aY)); } + + +void GeomAPI_Pnt::translate(const std::shared_ptr& theDir, double theDist) +{ + gp_Vec aVec(theDir->impl()); + aVec.Normalize(); + aVec.Multiply(theDist); + MY_PNT->Translate(aVec); +} diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h index c04dec42b..835e24939 100644 --- a/src/GeomAPI/GeomAPI_Pnt.h +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -51,6 +51,9 @@ class GEOMAPI_EXPORT GeomAPI_Pnt : public GeomAPI_Interface std::shared_ptr to2D(const std::shared_ptr& theOrigin, const std::shared_ptr& theDirX, const std::shared_ptr& theDirY); + + /// Translates the point along direction theDir on distance theDist + void translate(const std::shared_ptr& theDir, double theDist); }; #endif diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 3e6314a96..17f52eb5f 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -88,14 +88,15 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); if (!anAISIO.IsNull()) { myResult2AISObjectMap[theObject] = theAIS; + aContext->Display(anAISIO, false); + aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false); + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (aFeature.get() != NULL) { GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast(aFeature); if (aCustPrs.get() != NULL) aCustPrs->customisePresentation(theAIS); } - aContext->Display(anAISIO, false); - aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, isUpdateViewer); if (aContext->HasOpenedContext()) { if (myUseExternalObjects) { if (myActiveSelectionModes.size() == 0) @@ -108,6 +109,8 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, } } } + if (isUpdateViewer) + updateViewer(); } void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer)