1 // Copyright (C) 2007-2008 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
22 // GEOM OBJECT : interactive object for Geometry entities visualization
23 // File : GEOM_AISShape.cxx
24 // Author : Nicolas REJNERI
29 \class GEOM_AISShape GEOM_AISShape.hxx
33 #include "GEOM_AISShape.ixx"
34 #include "SALOME_InteractiveObject.hxx"
36 // Open CASCADE Includes
37 #include <AIS_Drawer.hxx>
38 #include <AIS_InteractiveContext.hxx>
40 #include <BRep_Tool.hxx>
42 #include <GCPnts_AbscissaPoint.hxx>
43 #include <GeomAdaptor_Curve.hxx>
47 #include <Graphic3d_AspectFillArea3d.hxx>
49 #include <Prs3d_ShadingAspect.hxx>
50 #include <Prs3d_Arrow.hxx>
52 #include <SelectBasics_SensitiveEntity.hxx>
53 #include <SelectMgr_EntityOwner.hxx>
54 #include <StdSelect_BRepOwner.hxx>
55 #include <SelectMgr_IndexedMapOfOwner.hxx>
56 #include <SelectMgr_Selection.hxx>
57 #include <StdSelect_DisplayMode.hxx>
58 #include <StdPrs_WFDeflectionShape.hxx>
60 #include <TColStd_IndexedMapOfInteger.hxx>
61 #include <TColStd_ListIteratorOfListOfInteger.hxx>
62 #include <TColStd_ListOfInteger.hxx>
64 #include <TopoDS_Shape.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
67 #include <TopExp_Explorer.hxx>
69 #include <TopoDS_Edge.hxx>
70 #include <TopoDS_Shape.hxx>
71 #include <TopoDS_Vertex.hxx>
75 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
76 const Handle(AIS_InteractiveContext)& theIC,
77 SelectMgr_IndexedMapOfOwner& theMap )
79 if ( theObj.IsNull() || theIC.IsNull() )
82 TColStd_ListOfInteger modes;
83 theIC->ActivatedModes( theObj, modes );
85 TColStd_ListIteratorOfListOfInteger itr( modes );
86 for (; itr.More(); itr.Next() ) {
88 if ( !theObj->HasSelection( m ) )
91 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
93 for ( sel->Init(); sel->More(); sel->Next() ) {
94 Handle(SelectBasics_SensitiveEntity) entity = sel->Sensitive();
95 if ( entity.IsNull() )
98 Handle(SelectMgr_EntityOwner) owner =
99 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
100 if ( !owner.IsNull() )
106 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
107 const TopoDS_Shape& aMainShape,
108 const SelectMgr_IndexedMapOfOwner& anAllMap,
109 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
111 TopTools_IndexedMapOfShape aMapOfShapes;
112 TopExp::MapShapes(aMainShape, aMapOfShapes);
114 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
115 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
116 if ( anOwner.IsNull() || !anOwner->HasShape() )
119 const TopoDS_Shape& aSubShape = anOwner->Shape();
120 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
121 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
124 if ( !aToHiliteMap.Contains( anOwner ) )
125 aToHiliteMap.Add( anOwner );
129 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
130 const Standard_CString aName)
131 : SALOME_AISShape(shape), myName(aName), myDisplayVectors(false)
133 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
136 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io){
140 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO(){
141 Handle(SALOME_InteractiveObject) IO;
142 if ( !GetOwner().IsNull() )
143 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
147 Standard_Boolean GEOM_AISShape::hasIO(){
148 return !getIO().IsNull();
151 void GEOM_AISShape::setName(const Standard_CString aName)
155 Handle(SALOME_InteractiveObject) IO = getIO();
160 Standard_CString GEOM_AISShape::getName(){
161 return myName.ToCString();
164 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
165 const Handle(Prs3d_Presentation)& aPrs,
166 const Standard_Integer aMode)
168 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
170 StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
173 case StdSelect_DM_Wireframe:
175 StdPrs_WFDeflectionShape::Add(aPrs,myshape,myDrawer);
178 case StdSelect_DM_Shading:
180 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
182 Graphic3d_MaterialAspect aMatAspect;
183 aMatAspect.SetAmbient( 0.5 );
184 aMatAspect.SetDiffuse( 0.5 );
185 aMatAspect.SetEmissive( 0.5 );
186 aMatAspect.SetShininess(0.5 );
187 aMatAspect.SetSpecular( 0.5 );
189 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
190 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Graphic3d_NOM_JADE);
192 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
193 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
194 FMat.SetTransparency(myTransparency); BMat.SetTransparency(myTransparency);
195 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
196 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
198 //Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
199 // P->SetPrimitivesAspect(a4bis);
200 // G->SetGroupPrimitivesAspect(a4bis);
201 //a4bis->SetInteriorColor(myShadingColor);
202 myDrawer->ShadingAspect()->SetColor(myShadingColor);
204 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
205 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
206 AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
213 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
214 for ( ; Exp.More(); Exp.Next() ) {
215 TopoDS_Vertex aV1, aV2;
216 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
218 if ( anEdgeE.IsNull() ) continue;
220 TopExp::Vertices(anEdgeE, aV1, aV2);
221 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
222 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
226 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
228 if ( C.IsNull() ) continue;
230 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
231 C->D1(lp, aP2, aDirVec);
233 C->D1(fp, aP1, aDirVec);
237 GeomAdaptor_Curve aAdC;
238 aAdC.Load(C, fp, lp);
239 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
241 if (aDist > gp::Resolution()) {
243 if ( anEdgeE.Orientation() == TopAbs_FORWARD )
248 Prs3d_Arrow::Draw(aPrs, aP2, aDir, PI/180.*5., aDist/10.);
252 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
255 void GEOM_AISShape::SetTransparency(const Standard_Real aValue)
257 if(aValue<0.0 || aValue>1.0) return;
265 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
266 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
267 FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
268 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
269 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
270 myTransparency = aValue;
273 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
275 myShadingColor = aCol;
278 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
279 const Standard_Boolean aHighlight )
281 Handle(AIS_InteractiveObject) anObj = this;
282 Handle(AIS_InteractiveContext) anIC = GetContext();
283 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
286 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
287 anIC->SetAutomaticHilight( false );
289 anIC->ClearSelected( false );
292 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
294 // Get entity owners for all activated selection modes
295 getEntityOwners( anObj, anIC, anAllMap );
297 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
298 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
301 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
302 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
305 anIC->SetAutomaticHilight( isAutoHilight );
306 anIC->HilightSelected( false );
309 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
311 myDisplayVectors = isDisplayed;