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 #include "utilities.h"
38 // Open CASCADE Includes
39 #include <AIS_Drawer.hxx>
40 #include <AIS_InteractiveContext.hxx>
41 #include <Graphic3d_AspectFillArea3d.hxx>
42 #include <Prs3d_Drawer.hxx>
43 #include <Prs3d_IsoAspect.hxx>
44 #include <Prs3d_LineAspect.hxx>
45 #include <Prs3d_ShadingAspect.hxx>
46 #include <SelectBasics_SensitiveEntity.hxx>
47 #include <SelectMgr_EntityOwner.hxx>
48 #include <StdSelect_BRepOwner.hxx>
49 #include <SelectMgr_IndexedMapOfOwner.hxx>
50 #include <SelectMgr_Selection.hxx>
51 #include <StdSelect_DisplayMode.hxx>
52 #include <StdPrs_WFShape.hxx>
53 #include <StdPrs_ShadedShape.hxx>
54 #include <TColStd_IndexedMapOfInteger.hxx>
55 #include <TColStd_ListIteratorOfListOfInteger.hxx>
56 #include <TColStd_ListOfInteger.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopTools_IndexedMapOfShape.hxx>
63 static void getEntityOwners( const Handle(AIS_InteractiveObject)& theObj,
64 const Handle(AIS_InteractiveContext)& theIC,
65 SelectMgr_IndexedMapOfOwner& theMap )
67 if ( theObj.IsNull() || theIC.IsNull() )
70 TColStd_ListOfInteger modes;
71 theIC->ActivatedModes( theObj, modes );
73 TColStd_ListIteratorOfListOfInteger itr( modes );
74 for (; itr.More(); itr.Next() ) {
76 if ( !theObj->HasSelection( m ) )
79 Handle(SelectMgr_Selection) sel = theObj->Selection( m );
81 for ( sel->Init(); sel->More(); sel->Next() ) {
82 Handle(SelectBasics_SensitiveEntity) entity = sel->Sensitive();
83 if ( entity.IsNull() )
86 Handle(SelectMgr_EntityOwner) owner =
87 Handle(SelectMgr_EntityOwner)::DownCast(entity->OwnerId());
88 if ( !owner.IsNull() )
94 static void indicesToOwners( const TColStd_IndexedMapOfInteger& aIndexMap,
95 const TopoDS_Shape& aMainShape,
96 const SelectMgr_IndexedMapOfOwner& anAllMap,
97 SelectMgr_IndexedMapOfOwner& aToHiliteMap )
99 TopTools_IndexedMapOfShape aMapOfShapes;
100 TopExp::MapShapes(aMainShape, aMapOfShapes);
102 for ( Standard_Integer i = 1, n = anAllMap.Extent(); i <= n; i++ ) {
103 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(anAllMap( i ));
104 if ( anOwner.IsNull() || !anOwner->HasShape() )
107 const TopoDS_Shape& aSubShape = anOwner->Shape();
108 Standard_Integer aSubShapeId = aMapOfShapes.FindIndex( aSubShape );
109 if ( !aSubShapeId || !aIndexMap.Contains( aSubShapeId ) )
112 if ( !aToHiliteMap.Contains( anOwner ) )
113 aToHiliteMap.Add( anOwner );
117 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
118 const Standard_CString aName)
119 : SALOME_AISShape(shape), myName(aName)
121 myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
124 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io){
128 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO(){
129 Handle(SALOME_InteractiveObject) IO;
130 if ( !GetOwner().IsNull() )
131 IO = Handle(SALOME_InteractiveObject)::DownCast( GetOwner() );
135 Standard_Boolean GEOM_AISShape::hasIO(){
136 return !getIO().IsNull();
139 void GEOM_AISShape::setName(const Standard_CString aName)
143 Handle(SALOME_InteractiveObject) IO = getIO();
148 Standard_CString GEOM_AISShape::getName(){
149 return myName.ToCString();
152 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
153 const Handle(Prs3d_Presentation)& aPrs,
154 const Standard_Integer aMode)
156 if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
158 StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
161 case StdSelect_DM_Wireframe:
163 StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
166 case StdSelect_DM_Shading:
168 myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
170 Graphic3d_MaterialAspect aMatAspect;
171 aMatAspect.SetAmbient( 0.5 );
172 aMatAspect.SetDiffuse( 0.5 );
173 aMatAspect.SetEmissive( 0.5 );
174 aMatAspect.SetShininess(0.5 );
175 aMatAspect.SetSpecular( 0.5 );
177 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
178 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Graphic3d_NOM_JADE);
180 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
181 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
182 FMat.SetTransparency(myTransparency); BMat.SetTransparency(myTransparency);
183 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
184 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
186 //Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
187 // P->SetPrimitivesAspect(a4bis);
188 // G->SetGroupPrimitivesAspect(a4bis);
189 //a4bis->SetInteriorColor(myShadingColor);
190 myDrawer->ShadingAspect()->SetColor(myShadingColor);
192 // PAL12113: AIS_Shape::Compute() works correctly with shapes containing no faces
193 //StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
194 AIS_Shape::Compute(aPresentationManager, aPrs, aMode);
198 // aPrs->ReCompute(); // for hidden line recomputation if necessary...
201 void GEOM_AISShape::SetTransparency(const Standard_Real aValue)
203 if(aValue<0.0 || aValue>1.0) return;
211 Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
212 Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
213 FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
214 myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
215 myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
216 myTransparency = aValue;
219 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
221 myShadingColor = aCol;
224 void GEOM_AISShape::highlightSubShapes(const TColStd_IndexedMapOfInteger& aIndexMap,
225 const Standard_Boolean aHighlight )
227 Handle(AIS_InteractiveObject) anObj = this;
228 Handle(AIS_InteractiveContext) anIC = GetContext();
229 if ( anIC.IsNull() || !anIC->HasOpenedContext() )
232 Standard_Boolean isAutoHilight = anIC->AutomaticHilight();
233 anIC->SetAutomaticHilight( false );
235 anIC->ClearSelected( false );
238 SelectMgr_IndexedMapOfOwner anAllMap, aToHiliteMap;
240 // Get entity owners for all activated selection modes
241 getEntityOwners( anObj, anIC, anAllMap );
243 // Convert <aIndexMap> into the map of owners to highlight/unhighlight
244 indicesToOwners( aIndexMap, Shape(), anAllMap, aToHiliteMap );
247 for ( Standard_Integer i = 1, n = aToHiliteMap.Extent(); i <= n; i++ )
248 anIC->AddOrRemoveSelected( aToHiliteMap( i ), false );
251 anIC->SetAutomaticHilight( isAutoHilight );
252 anIC->HilightSelected( false );