From: vsv Date: Wed, 22 Oct 2014 08:05:22 +0000 (+0400) Subject: AIS presentation for result is created X-Git-Tag: V_0.5~88 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dfe52d15bccf7cd7d3fec2dd842625dcc5df7437;p=modules%2Fshaper.git AIS presentation for result is created --- diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index fee9e00df..c7c5f4bdd 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -4,10 +4,10 @@ icon=":icons/sketch.png" tooltip="Select a face for extrusion" activate="true" - shape_types="face wire edge" + shape_types="face" use_subshapes="true" /> - + diff --git a/src/GeomAPI/GeomAPI_Wire.h b/src/GeomAPI/GeomAPI_Wire.h index de849ef93..4bc0e0cd9 100644 --- a/src/GeomAPI/GeomAPI_Wire.h +++ b/src/GeomAPI/GeomAPI_Wire.h @@ -5,8 +5,10 @@ #ifndef GEOMAPI_WIRE_H_ #define GEOMAPI_WIRE_H_ -#include -#include +#include "GeomAPI.h" +#include "GeomAPI_Edge.h" +#include "GeomAPI_Pnt.h" +#include "GeomAPI_Dir.h" #include @@ -37,6 +39,30 @@ class GEOMAPI_EXPORT GeomAPI_Wire : public GeomAPI_Shape void addEdge(boost::shared_ptr theEdge); std::list > getEdges(); + /// Returns True if the wire is defined in a plane + bool hasPlane() const { return myOrigin && myNorm && myDirX && myDirY; } + + /// Set/Get origin point + void setOrigin(const boost::shared_ptr& theOrigin) { myOrigin = theOrigin; } + boost::shared_ptr origin() const { return myOrigin; } + + /// Set/Get X direction vector + void setDirX(const boost::shared_ptr& theDirX) { myDirX = theDirX; } + boost::shared_ptr dirX() const { return myDirX; } + + /// Set/Get Y direction vector + void setDirY(const boost::shared_ptr& theDirY) { myDirY = theDirY; } + boost::shared_ptr dirY() const { return myDirY; } + + /// Set/Get Normal direction vector + void setNorm(const boost::shared_ptr& theNorm) { myNorm = theNorm; } + boost::shared_ptr norm() const { return myNorm; } + +private: + boost::shared_ptr myOrigin; + boost::shared_ptr myDirX; + boost::shared_ptr myDirY; + boost::shared_ptr myNorm; }; #endif diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 7641722e4..ddf454e2c 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -33,6 +33,7 @@ SET(PROJECT_HEADERS ModuleBase_WidgetLineEdit.h ModuleBase_WidgetMultiSelector.h ModuleBase_ViewerFilters.h + ModuleBase_ResultPrs.h ) SET(PROJECT_SOURCES @@ -59,12 +60,14 @@ SET(PROJECT_SOURCES ModuleBase_WidgetLineEdit.cpp ModuleBase_WidgetMultiSelector.cpp ModuleBase_ViewerFilters.cpp + ModuleBase_ResultPrs.cpp ) SET(PROJECT_LIBRARIES Config ModelAPI GeomAPI + GeomAlgoAPI ${QT_LIBRARIES} ${CAS_VIEWER} ${CAS_KERNEL} @@ -89,6 +92,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src/ModelAPI ${CMAKE_SOURCE_DIR}/src/GeomDataAPI ${CMAKE_SOURCE_DIR}/src/GeomAPI + ${CMAKE_SOURCE_DIR}/src/GeomAlgoAPI ) ADD_DEFINITIONS(-DMODULEBASE_EXPORTS ${CAS_DEFINITIONS}) diff --git a/src/ModuleBase/ModuleBase_ResultPrs.cpp b/src/ModuleBase/ModuleBase_ResultPrs.cpp new file mode 100644 index 000000000..a1ca0bdd9 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ResultPrs.cpp @@ -0,0 +1,74 @@ +// File: ModuleBase_ResultPrs.cpp +// Created: 21 October 2014 +// Author: Vitaly SMETANNIKOV + +#include "ModuleBase_ResultPrs.h" + +#include +#include +#include + +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape); +IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape); + +ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult) + : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false) +{ + boost::shared_ptr aShapePtr = ModelAPI_Tools::shape(theResult); + boost::shared_ptr aWirePtr = + boost::dynamic_pointer_cast(aShapePtr); + if (aWirePtr) { + if (aWirePtr->hasPlane() ) { + // If this is a wire with plane defined thin it is a sketch-like object + // It must have invisible faces + std::list > aFaces; + GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(), + aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces); + + BRep_Builder aBuilder; + TopoDS_Shape aShape = aWirePtr->impl(); + std::list>::const_iterator aIt; + for (aIt = aFaces.cbegin(); aIt != aFaces.cend(); ++aIt) { + TopoDS_Shape aFace = (*aIt)->impl(); + aBuilder.Add(aShape, aFace); + } + Set(aShape); + myIsSketchMode = true; + // Define number of ISO lines + //Handle(AIS_Drawer) aDrawer = Attributes(); + //Attributes()->SetIsoOnPlane(Standard_False); + //SetAttributes(aDrawer); + } else { + Set(aWirePtr->impl()); + } + } else { + Set(aShapePtr->impl()); + } +} + + +Standard_Boolean ModuleBase_ResultPrs::AcceptDisplayMode(const Standard_Integer theMode) const +{ + if (myIsSketchMode) { + return theMode == 0; + } + return AIS_Shape::AcceptDisplayMode(theMode); +} + +void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, + const Standard_Integer theMode) +{ + if (myIsSketchMode) { + Handle(AIS_Drawer) aDrawer = Attributes(); + aDrawer->SetIsoOnPlane(Standard_False); + aDrawer->UIsoAspect()->SetNumber(0); + aDrawer->VIsoAspect()->SetNumber(0); + SetAttributes(aDrawer); + } + AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); +} diff --git a/src/ModuleBase/ModuleBase_ResultPrs.h b/src/ModuleBase/ModuleBase_ResultPrs.h new file mode 100644 index 000000000..068cffe93 --- /dev/null +++ b/src/ModuleBase/ModuleBase_ResultPrs.h @@ -0,0 +1,38 @@ +// File: ModuleBase_ResultPrs.h +// Created: 21 October 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef ModuleBase_ResultPrs_H +#define ModuleBase_ResultPrs_H + +#include "ModuleBase.h" + +#include + +#include +#include + +DEFINE_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape) + +class ModuleBase_ResultPrs: public AIS_Shape +{ +public: + Standard_EXPORT ModuleBase_ResultPrs(ResultPtr theResult); + + Standard_EXPORT ResultPtr getResult() const { return myResult; } + + Standard_EXPORT virtual Standard_Boolean AcceptDisplayMode(const Standard_Integer theMode) const; + + DEFINE_STANDARD_RTTI(ModuleBase_ResultPrs) +protected: + void Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); + +private: + ResultPtr myResult; + + bool myIsSketchMode; +}; + + +#endif \ No newline at end of file diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index a8fef3263..19715af30 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -93,6 +93,11 @@ void SketchPlugin_Sketch::execute() for (; aShapeIt != aFeaturesPreview.end(); ++aShapeIt) { aBigWire->addEdge(*aShapeIt); } + aBigWire->setOrigin(anOrigin->pnt()); + aBigWire->setDirX(aDirX->dir()); + aBigWire->setDirY(aDirY->dir()); + aBigWire->setNorm(aNorm->dir()); + // GeomAlgoAPI_SketchBuilder::createFaces(anOrigin->pnt(), aDirX->dir(), aDirY->dir(), aNorm->dir(), // aFeaturesPreview, aLoops, aWires); boost::shared_ptr aConstr = document()->createConstruction(data()); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 8e0f38400..d281f86f0 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -12,6 +12,8 @@ #include #include +#include + #include #include @@ -59,7 +61,8 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer) boost::shared_ptr aShapePtr = ModelAPI_Tools::shape(aResult); if (aShapePtr) { anAIS = AISObjectPtr(new GeomAPI_AISObject()); - anAIS->createShape(aShapePtr); + anAIS->setImpl(new Handle(AIS_InteractiveObject)(new ModuleBase_ResultPrs(aResult))); + //anAIS->createShape(aShapePtr); isShading = true; } }