1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM OBJECT : interactive object for Geometry entities visualization
24 // File : GEOM_AISShape.cxx
25 // Author : Nicolas REJNERI
30 \class GEOM_AISShape GEOM_AISShape.hxx
34 #include "GEOM_AISShape.ixx"
35 #include "SALOME_InteractiveObject.hxx"
36 #include "GEOM_AISVector.hxx"
38 // Open CASCADE Includes
39 #include <AIS_Drawer.hxx>
40 #include <AIS_InteractiveContext.hxx>
42 #include <BRep_Tool.hxx>
44 #include <GCPnts_AbscissaPoint.hxx>
45 #include <GeomAdaptor_Curve.hxx>
49 #include <Graphic3d_AspectFillArea3d.hxx>
51 #include <Prs3d_ShadingAspect.hxx>
52 #include <Prs3d_Arrow.hxx>
54 #include <SelectBasics_SensitiveEntity.hxx>
55 #include <SelectMgr_EntityOwner.hxx>
56 #include <StdSelect_BRepOwner.hxx>
57 #include <SelectMgr_IndexedMapOfOwner.hxx>
58 #include <SelectMgr_Selection.hxx>
59 #include <StdSelect_DisplayMode.hxx>
60 #include <StdPrs_WFDeflectionShape.hxx>
62 #include <TColStd_IndexedMapOfInteger.hxx>
63 #include <TColStd_ListIteratorOfListOfInteger.hxx>
64 #include <TColStd_ListOfInteger.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <TopTools_IndexedMapOfShape.hxx>
69 #include <TopExp_Explorer.hxx>
71 #include <TopoDS_Edge.hxx>
72 #include <TopoDS_Shape.hxx>
73 #include <TopoDS_Vertex.hxx>
76 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
77 const Handle(AIS_InteractiveContext)& theIC,
78 SelectMgr_IndexedMapOfOwner& theMap )
80 if ( theObj.IsNull() || theIC.IsNull() )
83 TColStd_ListOfInteger modes;
84 theIC->ActivatedModes( theObj, modes );
86 TColStd_ListIteratorOfListOfInteger itr( modes );
87 for (; itr.More(); itr.Next() ) {
89 if ( !theObj->HasSelection( m ) )
92 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
94 for ( sel->Init(); sel->More(); sel->Next() ) {
95 Handle(SelectBasics_SensitiveEntity) entity = sel->Sensitive();
96 if ( entity.IsNull() )
99 Handle(SelectMgr_EntityOwner) owner =
100 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
101 if ( !owner.IsNull() )
107 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
108 const TopoDS_Shape& aMainShape,
109 const SelectMgr_IndexedMapOfOwner& anAllMap,
110 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
112 TopTools_IndexedMapOfShape aMapOfShapes;
113 TopExp::MapShapes(aMainShape, aMapOfShapes);
115 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
116 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
117 if ( anOwner.IsNull() || !anOwner->HasShape() )
120 const TopoDS_Shape& aSubShape = anOwner->Shape();
121 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
122 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
125 if ( !aToHiliteMap.Contains( anOwner ) )
126 aToHiliteMap.Add( anOwner );
130 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
131 const Standard_CString aName)
132 : SALOME_AISShape(shape), myName(aName), myDisplayVectors(false)
134 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
137 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io){
141 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO(){
142 Handle(SALOME_InteractiveObject) IO;
143 if ( !GetOwner().IsNull() )
144 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
148 Standard_Boolean GEOM_AISShape::hasIO(){
149 return !getIO().IsNull();
152 void GEOM_AISShape::setName(const Standard_CString aName)
156 Handle(SALOME_InteractiveObject) IO = getIO();
161 Standard_CString GEOM_AISShape::getName(){
162 return myName.ToCString();
165 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
166 const Handle(Prs3d_Presentation)& aPrs,
167 const Standard_Integer aMode)
169 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
171 StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
174 case StdSelect_DM_Wireframe:
176 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
179 case StdSelect_DM_Shading:
181 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
183 Graphic3d_MaterialAspect aMatAspect;
184 aMatAspect.SetAmbient( 0.5 );
185 aMatAspect.SetDiffuse( 0.5 );
186 aMatAspect.SetEmissive( 0.5 );
187 aMatAspect.SetShininess(0.5 );
188 aMatAspect.SetSpecular( 0.5 );
190 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
191 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Graphic3d_NOM_JADE);
193 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
194 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
195 FMat.SetTransparency(myTransparency); BMat.SetTransparency(myTransparency);
196 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
197 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
199 //Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
200 // P->SetPrimitivesAspect(a4bis);
201 // G->SetGroupPrimitivesAspect(a4bis);
202 //a4bis->SetInteriorColor(myShadingColor);
203 myDrawer->ShadingAspect()->SetColor(myShadingColor);
205 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
206 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
207 AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
214 const bool isVector = IsKind(STANDARD_TYPE(GEOM_AISVector));
215 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
216 for ( ; Exp.More(); Exp.Next() ) {
217 TopoDS_Vertex aV1, aV2;
218 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
220 // draw curve direction (issue 0021087)
221 anEdgeE.Orientation( TopAbs_FORWARD );
223 if ( anEdgeE.IsNull() ) continue;
225 TopExp::Vertices(anEdgeE, aV1, aV2);
226 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
227 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
231 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
233 if ( C.IsNull() ) continue;
235 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
236 C->D1(lp, aP2, aDirVec);
238 C->D1(fp, aP1, aDirVec);
242 GeomAdaptor_Curve aAdC;
243 aAdC.Load(C, fp, lp);
244 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
246 if (aDist > gp::Resolution()) {
248 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
253 Prs3d_Arrow::Draw(aPrs, aP2, aDir, PI/180.*5., aDist/10.);
257 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
260 void GEOM_AISShape::SetTransparency(const Standard_Real aValue)
262 if(aValue<0.0 || aValue>1.0) return;
270 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
271 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
272 FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
273 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
274 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
275 myTransparency = aValue;
278 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
280 myShadingColor = aCol;
283 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
284 const Standard_Boolean aHighlight )
286 Handle(AIS_InteractiveObject) anObj = this;
287 Handle(AIS_InteractiveContext) anIC = GetContext();
288 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
291 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
292 anIC->SetAutomaticHilight( false );
294 anIC->ClearSelected( false );
297 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
299 // Get entity owners for all activated selection modes
300 getEntityOwners( anObj, anIC, anAllMap );
302 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
303 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
306 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
307 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
310 anIC->SetAutomaticHilight( isAutoHilight );
311 anIC->HilightSelected( false );
314 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
316 myDisplayVectors = isDisplayed;