Salome HOME
NRI : Merge BRANCH_V1_2c
[modules/geom.git] / src / 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       
105       Graphic3d_MaterialAspect aMatAspect;
106       aMatAspect.SetAmbient( 1 );
107       aMatAspect.SetDiffuse( 0 );
108       aMatAspect.SetEmissive( 0 );
109       aMatAspect.SetShininess(1 );
110       aMatAspect.SetSpecular( 0 );
111       
112       myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(aMatAspect);
113       myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(Graphic3d_NOM_JADE);
114       
115       Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
116       Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
117       FMat.SetTransparency(myTransparency); BMat.SetTransparency(myTransparency);
118       myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
119       myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
120
121       //Handle(Graphic3d_AspectFillArea3d) a4bis = myDrawer->ShadingAspect()->Aspect();
122       //       P->SetPrimitivesAspect(a4bis);
123       //        G->SetGroupPrimitivesAspect(a4bis);
124       //a4bis->SetInteriorColor(myShadingColor);
125       myDrawer->ShadingAspect()->SetColor(myShadingColor);
126
127       StdPrs_ShadedShape::Add(aPrs,myshape,myDrawer);
128       break;
129     }
130   }
131   //  aPrs->ReCompute(); // for hidden line recomputation if necessary...
132 }
133
134 void GEOM_AISShape::SetTransparency(const Standard_Real aValue)
135 {
136   if(aValue<0.0 || aValue>1.0) return;
137   
138   if(aValue<=0.05) 
139     {
140       UnsetTransparency();
141       return;
142     }
143
144   Graphic3d_MaterialAspect FMat = myDrawer->ShadingAspect()->Aspect()->FrontMaterial();
145   Graphic3d_MaterialAspect BMat = myDrawer->ShadingAspect()->Aspect()->BackMaterial();
146   FMat.SetTransparency(aValue); BMat.SetTransparency(aValue);
147   myDrawer->ShadingAspect()->Aspect()->SetFrontMaterial(FMat);
148   myDrawer->ShadingAspect()->Aspect()->SetBackMaterial(BMat);
149   myTransparency = aValue;
150 }
151
152 void GEOM_AISShape::SetShadingColor(const Quantity_Color &aCol)
153 {
154   myShadingColor = aCol;
155 }