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>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <Prs3d_ShadingAspect.hxx>
41 #include <SelectBasics_SensitiveEntity.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <StdSelect_BRepOwner.hxx>
44 #include <SelectMgr_IndexedMapOfOwner.hxx>
45 #include <SelectMgr_Selection.hxx>
46 #include <StdSelect_DisplayMode.hxx>
47 #include <StdPrs_WFShape.hxx>
48 #include <TColStd_IndexedMapOfInteger.hxx>
49 #include <TColStd_ListIteratorOfListOfInteger.hxx>
50 #include <TColStd_ListOfInteger.hxx>
52 #include <TopoDS_Shape.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
55 #include <BRep_Tool.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <TopoDS_Edge.hxx>
60 #include <TopoDS_Shape.hxx>
61 #include <TopoDS_Vertex.hxx>
65 #include <Prs3d_Arrow.hxx>
66 #include <GeomAdaptor_Curve.hxx>
67 #include <GCPnts_AbscissaPoint.hxx>
71 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
72 const Handle(AIS_InteractiveContext)& theIC,
73 SelectMgr_IndexedMapOfOwner& theMap )
75 if ( theObj.IsNull() || theIC.IsNull() )
78 TColStd_ListOfInteger modes;
79 theIC->ActivatedModes( theObj, modes );
81 TColStd_ListIteratorOfListOfInteger itr( modes );
82 for (; itr.More(); itr.Next() ) {
84 if ( !theObj->HasSelection( m ) )
87 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
89 for ( sel->Init(); sel->More(); sel->Next() ) {
90 Handle(SelectBasics_SensitiveEntity) entity = sel->Sensitive();
91 if ( entity.IsNull() )
94 Handle(SelectMgr_EntityOwner) owner =
95 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
96 if ( !owner.IsNull() )
102 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
103 const TopoDS_Shape& aMainShape,
104 const SelectMgr_IndexedMapOfOwner& anAllMap,
105 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
107 TopTools_IndexedMapOfShape aMapOfShapes;
108 TopExp::MapShapes(aMainShape, aMapOfShapes);
110 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
111 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
112 if ( anOwner.IsNull() || !anOwner->HasShape() )
115 const TopoDS_Shape& aSubShape = anOwner->Shape();
116 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
117 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
120 if ( !aToHiliteMap.Contains( anOwner ) )
121 aToHiliteMap.Add( anOwner );
125 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
126 const Standard_CString aName)
127 : SALOME_AISShape(shape), myName(aName), myDisplayVectors(false)
129 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
132 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io){
136 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO(){
137 Handle(SALOME_InteractiveObject) IO;
138 if ( !GetOwner().IsNull() )
139 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
143 Standard_Boolean GEOM_AISShape::hasIO(){
144 return !getIO().IsNull();
147 void GEOM_AISShape::setName(const Standard_CString aName)
151 Handle(SALOME_InteractiveObject) IO = getIO();
156 Standard_CString GEOM_AISShape::getName(){
157 return myName.ToCString();
160 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
161 const Handle(Prs3d_Presentation)& aPrs,
162 const Standard_Integer aMode)
164 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
166 StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
169 case StdSelect_DM_Wireframe:
171 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
174 case StdSelect_DM_Shading:
176 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
178 Graphic3d_MaterialAspect aMatAspect;
179 aMatAspect.SetAmbient( 0.5 );
180 aMatAspect.SetDiffuse( 0.5 );
181 aMatAspect.SetEmissive( 0.5 );
182 aMatAspect.SetShininess(0.5 );
183 aMatAspect.SetSpecular( 0.5 );
185 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
186 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Graphic3d_NOM_JADE);
188 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
189 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
190 FMat.SetTransparency(myTransparency); BMat.SetTransparency(myTransparency);
191 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
192 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
194 //Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
195 // P->SetPrimitivesAspect(a4bis);
196 // G->SetGroupPrimitivesAspect(a4bis);
197 //a4bis->SetInteriorColor(myShadingColor);
198 myDrawer->ShadingAspect()->SetColor(myShadingColor);
200 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
201 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
202 AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
209 TopExp_Explorer Exp ( myshape, TopAbs_EDGE );
210 for ( ; Exp.More(); Exp.Next() ) {
211 TopoDS_Vertex aV1, aV2;
212 TopoDS_Edge anEdgeE = TopoDS::Edge(Exp.Current());
213 TopExp::Vertices(anEdgeE, aV1, aV2);
214 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
215 gp_Pnt aP2 = BRep_Tool::Pnt(aV2);
219 Handle(Geom_Curve) C = BRep_Tool::Curve(anEdgeE,fp,lp);
220 C->D1(lp, aP2, aDirVec);
222 GeomAdaptor_Curve aAdC;
223 aAdC.Load(C, fp, lp);
224 Standard_Real aDist = GCPnts_AbscissaPoint::Length(aAdC, fp, lp);
226 if (aDist > gp::Resolution()) {
227 gp_Dir aDir (aDirVec);
228 Prs3d_Arrow::Draw(aPrs, aP2, aDir, PI/180.*5., aDist/10.);
232 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
235 void GEOM_AISShape::SetTransparency(const Standard_Real aValue)
237 if(aValue<0.0 || aValue>1.0) return;
245 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
246 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
247 FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
248 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
249 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
250 myTransparency = aValue;
253 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
255 myShadingColor = aCol;
258 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
259 const Standard_Boolean aHighlight )
261 Handle(AIS_InteractiveObject) anObj = this;
262 Handle(AIS_InteractiveContext) anIC = GetContext();
263 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
266 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
267 anIC->SetAutomaticHilight( false );
269 anIC->ClearSelected( false );
272 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
274 // Get entity owners for all activated selection modes
275 getEntityOwners( anObj, anIC, anAllMap );
277 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
278 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
281 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
282 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
285 anIC->SetAutomaticHilight( isAutoHilight );
286 anIC->HilightSelected( false );
289 void GEOM_AISShape::SetDisplayVectors(bool isDisplayed)
291 myDisplayVectors = isDisplayed;