]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_ResultPrs.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_ResultPrs.cpp
1 // File:        ModuleBase_ResultPrs.cpp
2 // Created:     21 October 2014
3 // Author:      Vitaly SMETANNIKOV
4
5 #include "ModuleBase_ResultPrs.h"
6
7 #include <ModelAPI_Tools.h>
8 #include <GeomAPI_Wire.h>
9 #include <GeomAlgoAPI_SketchBuilder.h>
10
11 #include <BRep_Builder.hxx>
12 #include <AIS_Drawer.hxx>
13 #include <Prs3d_IsoAspect.hxx>
14
15 IMPLEMENT_STANDARD_HANDLE(ModuleBase_ResultPrs, AIS_Shape);
16 IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ResultPrs, AIS_Shape);
17
18 ModuleBase_ResultPrs::ModuleBase_ResultPrs(ResultPtr theResult)
19   : AIS_Shape(TopoDS_Shape()), myResult(theResult), myIsSketchMode(false)
20 {
21   boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
22   boost::shared_ptr<GeomAPI_Wire> aWirePtr = 
23     boost::dynamic_pointer_cast<GeomAPI_Wire>(aShapePtr);
24   if (aWirePtr) {
25     if (aWirePtr->hasPlane() ) {
26       // If this is a wire with plane defined thin it is a sketch-like object
27       // It must have invisible faces
28       std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
29       GeomAlgoAPI_SketchBuilder::createFaces(aWirePtr->origin(), aWirePtr->dirX(),
30         aWirePtr->dirY(), aWirePtr->norm(), aWirePtr, aFaces);
31
32       BRep_Builder aBuilder;
33       TopoDS_Shape aShape = aWirePtr->impl<TopoDS_Shape>();
34       std::list<boost::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
35       for (aIt = aFaces.cbegin(); aIt != aFaces.cend(); ++aIt) {
36         TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
37         aBuilder.Add(aShape, aFace);
38       }
39       Set(aShape);
40       myIsSketchMode = true;
41       // Define number of ISO lines
42       //Handle(AIS_Drawer) aDrawer = Attributes();
43       //Attributes()->SetIsoOnPlane(Standard_False);
44       //SetAttributes(aDrawer);
45     } else {
46       Set(aWirePtr->impl<TopoDS_Shape>());
47     }
48   } else {
49     Set(aShapePtr->impl<TopoDS_Shape>());
50   }
51 }
52
53
54 Standard_Boolean ModuleBase_ResultPrs::AcceptDisplayMode(const Standard_Integer theMode) const
55 {
56   if (myIsSketchMode) {
57     return theMode == 0;
58   }
59   return AIS_Shape::AcceptDisplayMode(theMode);
60 }
61
62 void ModuleBase_ResultPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
63                                    const Handle(Prs3d_Presentation)& thePresentation, 
64                                    const Standard_Integer theMode)
65 {
66   if (myIsSketchMode) {
67     Handle(AIS_Drawer) aDrawer = Attributes();
68     aDrawer->SetIsoOnPlane(Standard_False);
69     aDrawer->UIsoAspect()->SetNumber(0);
70     aDrawer->VIsoAspect()->SetNumber(0);
71     SetAttributes(aDrawer);
72   }
73   AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
74 }