Salome HOME
sources v1.2
[modules/geom.git] / OBJECT / GEOM_AISShape.cxx
1 //  GEOM OBJECT : interactive object for Geometry entities visualization
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GEOM_AISShape.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 /*!
31   \class GEOM_AISShape GEOM_AISShape.hxx
32   \brief ....
33 */
34
35 #include "GEOM_AISShape.ixx"
36 #include "SALOME_InteractiveObject.hxx"
37
38 #include "utilities.h"
39
40 // Open CASCADE Includes
41 #include <AIS_Drawer.hxx>
42 #include <Prs3d_Drawer.hxx>
43 #include <Prs3d_IsoAspect.hxx>
44 #include <Prs3d_LineAspect.hxx>
45 #include <Prs3d_ShadingAspect.hxx>
46 #include <StdSelect_DisplayMode.hxx>
47 #include <StdPrs_WFShape.hxx>
48 #include <StdPrs_ShadedShape.hxx>
49
50 #include <Graphic3d_AspectFillArea3d.hxx>
51
52 GEOM_AISShape::GEOM_AISShape(const TopoDS_Shape& shape,
53                              const Standard_CString aName): SALOME_AISShape(shape)
54 {
55   myIO = NULL;
56   myName = new char [strlen(aName)+1];
57   strcpy( myName, aName);
58
59   myShadingColor = Quantity_Color( Quantity_NOC_GOLDENROD );
60 }
61
62 void GEOM_AISShape::setIO(const Handle(SALOME_InteractiveObject)& io){
63   myIO = io;
64 }
65
66 Handle(SALOME_InteractiveObject) GEOM_AISShape::getIO(){
67   return myIO;
68 }
69
70 Standard_Boolean GEOM_AISShape::hasIO(){
71   return !( myIO == NULL ) ;
72 }
73
74 void GEOM_AISShape::setName(const Standard_CString aName)
75 {
76   myName = new char [strlen(aName)+1];
77   strcpy( myName, aName);
78
79   if ( hasIO() )
80     myIO->setName(aName);
81 }
82
83 Standard_CString GEOM_AISShape::getName(){
84   return myName;
85 }
86
87 void GEOM_AISShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
88                             const Handle(Prs3d_Presentation)& aPrs,
89                             const Standard_Integer aMode)
90 {  
91   if (IsInfinite()) aPrs->SetInfiniteState(Standard_True); //pas de prise en compte lors du FITALL
92   
93   StdSelect_DisplayMode d = (StdSelect_DisplayMode) aMode;
94
95   switch (d) {
96   case StdSelect_DM_Wireframe: 
97     {
98       StdPrs_WFShape::Add(aPrs,myshape,myDrawer);
99       break;
100     }
101   case StdSelect_DM_Shading:
102     {
103       myDrawer->ShadingAspect()->Aspect()->SetDistinguishOn();
104       myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(Graphic3d_NOM_BRASS);
105       myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Graphic3d_NOM_JADE);
106
107       Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
108       Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
109       FMat.SetTransparency(myTransparency); BMat.SetTransparency(myTransparency);
110       myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
111       myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
112
113       //Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
114       //       P->SetPrimitivesAspect(a4bis);
115       //        G->SetGroupPrimitivesAspect(a4bis);
116       //a4bis->SetInteriorColor(myShadingColor);
117       myDrawer->ShadingAspect()->SetColor(myShadingColor);
118
119       StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
120       break;
121     }
122   }
123   //  aPrs->ReCompute(); // for hidden line recomputation if necessary...
124 }
125
126 void GEOM_AISShape::SetTransparency(const Standard_Real aValue)
127 {
128   if(aValue<0.0 || aValue>1.0) return;
129   
130   if(aValue<=0.05) 
131     {
132       UnsetTransparency();
133       return;
134     }
135
136   Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
137   Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
138   FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
139   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
140   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
141   myTransparency = aValue;
142 }
143
144 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
145 {
146   myShadingColor = aCol;
147 }