]> SALOME platform Git repositories - modules/geom.git/blob - src/OBJECT/GEOM_Actor.cxx
Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM OBJECT : interactive object for Geometry entities visualization
23 //  File   : GEOM_Actor.cxx
24 //  Author : Christophe ATTANASIO
25 //  Module : GEOM
26 //  $Header$
27 //
28 /*!
29   \class GEOM_Actor GEOM_Actor.h
30   \brief This class allows to display an OpenCASCADE CAD model in a VTK viewer.
31 */
32 #include "GEOM_Actor.h" 
33  
34 #include "GEOM_DeviceActor.h" 
35 #include "GEOM_VertexSource.h" 
36 #include "GEOM_EdgeSource.h" 
37 #include "GEOM_WireframeFace.h" 
38 #include "GEOM_ShadingFace.h"
39 #include "SVTK_Actor.h"
40
41 #include <vtkObjectFactory.h> 
42 #include <vtkRenderer.h> 
43 #include <vtkProperty.h> 
44 #include <vtkPointPicker.h>
45 #include <vtkCellPicker.h>
46  
47 #include <TopAbs_ShapeEnum.hxx>
48 #include <TopExp_Explorer.hxx>
49 #include <Poly_Triangulation.hxx>
50 #include <BRepMesh_IncrementalMesh.hxx>
51 #include <Bnd_Box.hxx>
52 #include <TopoDS.hxx>
53 #include <BRep_Tool.hxx>
54 #include <BRepBndLib.hxx>
55 #include <TopTools_ListOfShape.hxx>
56 #include <TopoDS_Iterator.hxx>
57 #include <TopExp.hxx>
58  
59 #include <vtkPolyDataWriter.h> 
60  
61 #include <vtkAppendPolyData.h>  
62 #include <vtkPolyDataMapper.h>  
63 #include <vtkPolyData.h>  
64 #include <vtkTransform.h>
65 #include <vtkMatrix4x4.h>
66 #include <vtkMath.h>
67 #include <vtkCamera.h>
68
69 #include "utilities.h"
70
71 //vtkStandardNewMacro(GEOM_Actor);
72
73 #ifndef MYDEBUG
74 //#define MYDEBUG
75 #endif
76
77 GEOM_Actor::GEOM_Actor(): 
78   //  myDisplayMode(eWireframe), 
79   myIsSelected(false), 
80  
81   myVertexActor(GEOM_DeviceActor::New(),true), 
82   myVertexSource(GEOM_VertexSource::New(),true), 
83  
84   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
85   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
86  
87   myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), 
88   myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), 
89  
90   mySharedEdgeActor(GEOM_DeviceActor::New(),true), 
91   mySharedEdgeSource(GEOM_EdgeSource::New(),true), 
92  
93   myWireframeFaceActor(GEOM_DeviceActor::New(),true), 
94   myWireframeFaceSource(GEOM_WireframeFace::New(),true), 
95  
96   myShadingFaceActor(GEOM_DeviceActor::New(),true), 
97   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
98  
99   myHighlightActor(GEOM_DeviceActor::New(),true), 
100   myAppendFilter(vtkAppendPolyData::New(),true), 
101   myPolyDataMapper(vtkPolyDataMapper::New(),true),
102
103   myHighlightProp(vtkProperty::New()),
104   myPreHighlightProp(vtkProperty::New()),
105   myShadingFaceProp(vtkProperty::New())
106   
107
108 #ifdef MYDEBUG
109   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
110 #endif
111
112   myPolyDataMapper->SetInput(myAppendFilter->GetOutput()); 
113   vtkProperty* aProperty; 
114
115   myHighlightProp->SetAmbient(0.5);
116   myHighlightProp->SetDiffuse(0.3);
117   myHighlightProp->SetSpecular(0.2);
118   myHighlightProp->SetRepresentationToSurface();
119   myHighlightProp->SetAmbientColor(1, 1, 1);
120   myHighlightProp->SetDiffuseColor(1, 1, 1);
121   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
122   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
123
124   this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
125
126   myPreHighlightProp->SetColor(0,1,1);
127   myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
128   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
129   myPreHighlightProp->SetRepresentationToWireframe();
130
131   myAppendFilter->AddInput(myVertexSource->GetOutput()); 
132   myVertexActor->SetInput(myVertexSource->GetOutput(),false); 
133   aProperty = myVertexActor->GetProperty(); 
134   aProperty->SetRepresentation(VTK_POINTS); 
135   aProperty->SetPointSize(3); 
136   aProperty->SetColor(1, 1, 0);
137  
138   myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput()); 
139   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); 
140   aProperty = myIsolatedEdgeActor->GetProperty(); 
141   aProperty->SetRepresentation(VTK_WIREFRAME); 
142   aProperty->SetColor(1, 0, 0);
143  
144   myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput()); 
145   myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); 
146   aProperty = myOneFaceEdgeActor->GetProperty(); 
147   aProperty->SetRepresentation(VTK_WIREFRAME); 
148   aProperty->SetColor(0, 1, 0);
149  
150   myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); 
151   mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); 
152   aProperty = mySharedEdgeActor->GetProperty(); 
153   aProperty->SetRepresentation(VTK_WIREFRAME); 
154   aProperty->SetColor(1, 1, 0);
155  
156   myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); 
157   myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); 
158   aProperty = myWireframeFaceActor->GetProperty(); 
159   aProperty->SetRepresentation(VTK_WIREFRAME); 
160   aProperty->SetColor(0.5, 0.5, 0.5);
161
162   myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true); 
163
164   myShadingFaceProp->SetRepresentation(VTK_SURFACE); 
165   myShadingFaceProp->SetInterpolationToGouraud(); 
166   myShadingFaceProp->SetAmbient(1.0);
167   myShadingFaceProp->SetDiffuse(1.0);
168   myShadingFaceProp->SetSpecular(0.4);
169   myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
170   myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
171   myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
172
173   myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
174
175   // Toggle display mode 
176   setDisplayMode(0); // WIRE FRAME
177
178
179  
180  
181 GEOM_Actor::~GEOM_Actor() 
182
183 #ifdef MYDEBUG
184   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
185 #endif
186   myHighlightProp->Delete();
187   myPreHighlightProp->Delete();
188   myShadingFaceProp->Delete();
189
190  
191 GEOM_Actor*  
192 GEOM_Actor:: 
193 New() 
194
195   GEOM_Actor* anObject = new GEOM_Actor(); 
196   anObject->SetMapper(anObject->myPolyDataMapper.Get()); 
197   return anObject; 
198
199  
200  
201 void Write(vtkPolyData* theDataSet, const char* theFileName){ 
202   vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); 
203   MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()); 
204   aWriter->SetInput(theDataSet); 
205   aWriter->SetFileName(theFileName); 
206   //aWriter->Write(); 
207   aWriter->Delete(); 
208
209  
210 void 
211 GEOM_Actor:: 
212 SetModified() 
213
214   this->myVertexSource->Modified(); 
215   this->myIsolatedEdgeSource->Modified(); 
216   this->myOneFaceEdgeSource->Modified(); 
217   this->mySharedEdgeSource->Modified(); 
218   this->myWireframeFaceSource->Modified(); 
219   this->myShadingFaceSource->Modified(); 
220
221
222 void  
223 GEOM_Actor:: 
224 SetMapper(vtkMapper* theMapper) 
225
226   SALOME_Actor::SetMapper(theMapper); 
227
228
229 void 
230 GEOM_Actor:: 
231 AddToRender(vtkRenderer* theRenderer)
232 {
233   //SALOME_Actor::AddToRender(theRenderer);
234   
235   theRenderer->AddActor(this); 
236  
237   this->myHighlightActor->AddToRender(theRenderer); 
238   
239
240   myShadingFaceActor->AddToRender(theRenderer); 
241   myWireframeFaceActor->AddToRender(theRenderer); 
242  
243   mySharedEdgeActor->AddToRender(theRenderer); 
244   myOneFaceEdgeActor->AddToRender(theRenderer); 
245   myIsolatedEdgeActor->AddToRender(theRenderer); 
246  
247   myVertexActor->AddToRender(theRenderer); 
248 }
249  
250 void 
251 GEOM_Actor:: 
252 RemoveFromRender(vtkRenderer* theRenderer)
253 {
254   //SALOME_Actor::RemoveFromRender(theRenderer);
255
256   
257   theRenderer->RemoveActor(this);
258
259   myHighlightActor->RemoveFromRender(theRenderer); 
260   myShadingFaceActor->RemoveFromRender(theRenderer); 
261   myWireframeFaceActor->RemoveFromRender(theRenderer); 
262  
263   mySharedEdgeActor->RemoveFromRender(theRenderer); 
264   myOneFaceEdgeActor->RemoveFromRender(theRenderer); 
265   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
266  
267   myVertexActor->RemoveFromRender(theRenderer);
268
269   
270   SetSelected(false);
271   SetVisibility(false);
272 }
273
274 void  
275 GEOM_Actor:: 
276 setDisplayMode(int theMode) 
277
278 #ifdef MYDEBUG
279   MESSAGE ( "GEOM_Actor::SetDisplayMode = "<<theMode );
280 #endif
281   VTKViewer_Actor::setDisplayMode(theMode);
282   SetVisibility(GetVisibility()); 
283
284
285 void  
286 GEOM_Actor:: 
287 SetSelected(bool theIsSelected) 
288
289 #ifdef MYDEBUG
290   MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected  );
291 #endif
292
293   myIsSelected = theIsSelected; 
294   SetVisibility(GetVisibility()); 
295
296
297 void  
298 GEOM_Actor:: 
299 SetVisibility(int theVisibility) 
300
301 #ifdef MYDEBUG
302   MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<"  myIsSelected="<< myIsSelected
303             << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
304 #endif
305
306   SALOME_Actor::SetVisibility(theVisibility);
307
308   this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
309   
310   myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading) && (!myIsSelected || !myIsPreselected)); 
311   myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode ==(int)eWireframe) && !myIsSelected);
312
313   mySharedEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
314   myOneFaceEdgeActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);
315   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
316
317 //  myVertexActor->SetVisibility(false);// must be added new mode points 
318   myVertexActor->SetVisibility(theVisibility);
319 }
320  
321
322 void
323 GEOM_Actor
324 ::SetNbIsos(const int theNb[2])
325 {
326   myWireframeFaceSource->SetNbIso(theNb);
327 }
328
329 void
330 GEOM_Actor
331 ::GetNbIsos(int &theNbU,int &theNbV)
332 {
333   myWireframeFaceSource->GetNbIso(theNbU, theNbV);
334 }
335
336 static 
337 void 
338 MeshShape(const TopoDS_Shape& theShape,
339           float& theDeflection, 
340           bool theIsRelative)
341
342   static Standard_Real RELATIVE_DEFLECTION = 0.0001; 
343   Standard_Real aDeflection = theDeflection; 
344
345   if(theDeflection <= 0) { // Compute default theDeflection
346     Bnd_Box B;
347     BRepBndLib::Add(theShape, B);
348     Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
349     B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
350     Standard_Real aDiagonal = (aXmax-aXmin)*(aXmax-aXmin) +
351                               (aYmax-aYmin)*(aYmax-aYmin) +
352                               (aZmax-aZmin)*(aZmax-aZmin);
353     aDiagonal = sqrt(aDiagonal); 
354     aDeflection = aDiagonal*RELATIVE_DEFLECTION; 
355  
356     if(theIsRelative) 
357       theDeflection = RELATIVE_DEFLECTION; 
358     else 
359       theDeflection = aDeflection; 
360   }
361   
362   BRepMesh_IncrementalMesh aMesh(theShape,aDeflection);
363 }
364
365 void  
366 GEOM_Actor:: 
367 SetDeflection(float theDeflection, bool theIsRelative) 
368
369   myDeflection = theDeflection; 
370   myIsRelative = theIsRelative; 
371  
372   MeshShape(myShape,myDeflection,myIsRelative); 
373  
374   SetModified(); 
375
376
377 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
378                            float theDeflection,
379                            bool theIsRelative,
380                            bool theIsVector)
381 {
382   myShape = theShape;
383
384   myVertexSource->Clear();
385   myIsolatedEdgeSource->Clear();
386   myOneFaceEdgeSource->Clear();
387   mySharedEdgeSource->Clear();
388   myWireframeFaceSource->Clear();
389   myShadingFaceSource->Clear();
390
391   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
392   for (; aVertexExp.More(); aVertexExp.Next())
393   {
394      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
395      myVertexSource->AddVertex(aVertex);
396   }
397   SetDeflection(theDeflection, theIsRelative);
398
399   // look if edges are free or shared
400   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
401   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
402
403   SetShape(theShape,anEdgeMap,theIsVector);
404 }
405
406 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
407                            const TopTools_IndexedDataMapOfShapeListOfShape& theEdgeMap,
408                            bool theIsVector)
409 {
410   if (theShape.ShapeType() == TopAbs_COMPOUND) {
411     TopoDS_Iterator anItr(theShape);
412     for (; anItr.More(); anItr.Next()) {
413       SetShape(anItr.Value(),theEdgeMap,theIsVector);
414     }
415   }
416
417   switch (theShape.ShapeType()) {
418     case TopAbs_WIRE: {
419       TopExp_Explorer anEdgeExp(theShape,TopAbs_EDGE);
420       for (; anEdgeExp.More(); anEdgeExp.Next()){
421         const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
422         if (!BRep_Tool::Degenerated(anEdge))
423           myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
424       }
425       break;
426     }
427     case TopAbs_EDGE: {
428       const TopoDS_Edge& anEdge = TopoDS::Edge(theShape);
429       if (!BRep_Tool::Degenerated(anEdge))
430         myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
431       break;
432     }
433     case TopAbs_VERTEX: {
434       break;
435     }
436     default: {
437       TopExp_Explorer aFaceExp (theShape,TopAbs_FACE);
438       for(; aFaceExp.More(); aFaceExp.Next()) {
439         const TopoDS_Face& aFace = TopoDS::Face(aFaceExp.Current());
440         myWireframeFaceSource->AddFace(aFace);
441         myShadingFaceSource->AddFace(aFace);
442         TopExp_Explorer anEdgeExp(aFaceExp.Current(), TopAbs_EDGE);
443         for(; anEdgeExp.More(); anEdgeExp.Next()) {
444           const TopoDS_Edge& anEdge = TopoDS::Edge(anEdgeExp.Current());
445           if(!BRep_Tool::Degenerated(anEdge)){
446             // compute the number of faces
447             int aNbOfFaces = theEdgeMap.FindFromKey(anEdge).Extent();
448             switch(aNbOfFaces){
449             case 0:  // isolated edge
450               myIsolatedEdgeSource->AddEdge(anEdge,theIsVector);
451               break;
452             case 1:  // edge in only one face
453               myOneFaceEdgeSource->AddEdge(anEdge,theIsVector);
454               break;
455             default: // edge shared by at least two faces
456               mySharedEdgeSource->AddEdge(anEdge,theIsVector);
457             }
458           }
459         }
460       }
461     }
462   }
463 }
464
465 // OLD METHODS
466 void GEOM_Actor::setDeflection(double adef) {
467 #ifdef MYDEBUG
468   MESSAGE ( "GEOM_Actor::setDeflection" );
469 #endif
470   SetDeflection((float)adef,GetIsRelative());
471 }
472
473
474 // warning! must be checked!
475 // SetHighlightProperty
476 // SetWireframeProperty
477 // SetShadingProperty
478
479 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
480 {
481 #ifdef MYDEBUG
482   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
483 #endif
484   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
485   
486 }
487
488 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
489 {
490 #ifdef MYDEBUG
491   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
492 #endif
493   // must be filled
494   myWireframeFaceActor->SetProperty(Prop);
495 }
496
497 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
498 {
499 #ifdef MYDEBUG
500   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
501 #endif
502   myShadingFaceProp->DeepCopy(Prop);
503 }
504
505
506 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
507 {
508 #ifdef MYDEBUG
509   MESSAGE ( "GEOM_Actor::Render" );
510 #endif
511
512   if(!GetVisibility())
513     return;
514
515   /* render the property */
516   if (!this->Property) {
517     // force creation of a property
518     this->GetProperty();
519     this->Property->SetInterpolation(1);
520     this->Property->SetRepresentationToSurface();
521     this->Property->SetAmbient(0.3);
522     this->Property->SetAmbientColor(0.88,0.86,0.2);
523     this->Property->SetDiffuseColor(0.99,0.7,0.21);
524     this->Property->SetSpecularColor(0.99,0.98,0.83);
525   }
526
527   switch(myDisplayMode){
528   case 0://wireframe
529     myPreHighlightProp->SetRepresentationToWireframe();
530     myHighlightProp->SetRepresentationToWireframe();
531     break;
532   case 1://shading
533     myPreHighlightProp->SetRepresentationToSurface();
534     myHighlightProp->SetRepresentationToSurface();
535     break;
536   }
537
538   if(!myIsSelected){
539     if(myIsPreselected){
540       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
541       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
542     } else {
543       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
544       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
545     }
546   }
547   else{
548     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
549     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
550   }
551
552   this->Property->Render(this, ren);
553   if (this->BackfaceProperty) {
554     this->BackfaceProperty->BackfaceRender(this, ren);
555     this->Device->SetBackfaceProperty(this->BackfaceProperty);
556   }
557   this->Device->SetProperty(this->Property);
558   if(myShape.ShapeType() == TopAbs_VERTEX) {
559     if(ren){
560       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
561       static vtkFloatingPointType delta = 0.01;
562       vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
563       ren->ViewToWorld(X1,Y1,Z1);
564       vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
565       ren->ViewToWorld(X2,Y2,Z2);
566       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
567       this->SetScale(Z2*delta);
568     }
569     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
570     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
571     this->Device->SetUserMatrix(aMatrix);
572     this->Device->Render(ren,theMapper);
573     aMatrix->Delete();    
574   } else
575     this->Device->Render(ren, theMapper);
576 }
577
578 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
579 {
580 #ifdef MYDEBUG
581   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
582 #endif  
583 }
584
585
586
587 void GEOM_Actor::ShallowCopy(vtkProp *prop)
588 {
589 #ifdef MYDEBUG
590   MESSAGE ( "GEOM_Actor::ShallowCopy" );
591 #endif
592   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
593   if ( f != NULL )
594     {
595       this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
596     }
597
598   // Now do superclass
599   this->SALOME_Actor::ShallowCopy(prop);
600 }
601
602 const TopoDS_Shape& GEOM_Actor::getTopo() {
603 #ifdef MYDEBUG
604   MESSAGE ( "GEOM_Actor::getTopo" );
605 #endif
606   return myShape;
607 }
608
609 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
610                                int imode, bool isVector)
611 {
612 #ifdef MYDEBUG
613   MESSAGE ( "GEOM_Actor::setInputShape" );
614 #endif
615 }
616
617 double GEOM_Actor::getDeflection()
618 {
619 #ifdef MYDEBUG
620   MESSAGE ( "GEOM_Actor::getDeflection" );
621 #endif
622   return (double) GetDeflection();
623 }
624
625
626 double GEOM_Actor::isVector()
627 {
628 #ifdef MYDEBUG
629   MESSAGE ( "GEOM_Actor::isVector" );
630 #endif  
631   return 0;
632 }
633
634 void GEOM_Actor::SubShapeOn()
635 {
636 #ifdef MYDEBUG
637   MESSAGE ( "GEOM_Actor::SubShapeOn" );
638 #endif  
639 }
640
641 void GEOM_Actor::SubShapeOff()
642 {
643 #ifdef MYDEBUG
644   MESSAGE ( "GEOM_Actor::SubShapeOff" );
645 #endif
646 }
647
648 void GEOM_Actor::highlight(bool highlight)
649 {
650 #ifdef MYDEBUG
651   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
652 #endif
653   SALOME_Actor::highlight(highlight);
654 }
655
656 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
657 {
658   // enk:tested OK
659   myShadingFaceProp->SetOpacity(opa);
660   myHighlightProp->SetOpacity(opa);
661   myPreHighlightProp->SetOpacity(opa);
662 }
663
664 vtkFloatingPointType GEOM_Actor::GetOpacity()
665 {
666   // enk:tested OK
667   return myShadingFaceProp->GetOpacity(); 
668 }
669
670 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
671 {
672   // enk:tested OK
673   myShadingFaceProp->SetColor(r,g,b);                          // shading color (Shading)
674   myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b);         // standalone edge color (Wireframe)
675   myVertexActor->GetProperty()->SetColor(r,g,b);               // vertex actor (Shading/Wireframe)
676   myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b);          // standalone face edge color (Wireframe)
677   mySharedEdgeActor->GetProperty()->SetColor(r,g,b);           // share edge color (Wireframe)
678 }
679
680 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
681 {
682   // enk:tested OK
683   vtkFloatingPointType aRGB[3];
684   myShadingFaceProp->GetColor(aRGB);
685   r = aRGB[0];
686   g = aRGB[1];
687   b = aRGB[2];
688 }
689
690 bool GEOM_Actor::IsInfinitive()
691 {
692   return (bool)(myShape.Infinite());
693 }
694
695 /*!
696   To map current selection to VTK representation
697 */
698 void
699 GEOM_Actor
700 ::Highlight(bool theIsHighlight)
701 {
702   myIsSelected = theIsHighlight;
703 #ifdef MYDEBUG
704   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
705 #endif
706   
707   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
708   SetVisibility(GetVisibility());
709 }
710
711 /*!
712   To process prehighlight (called from SVTK_InteractorStyle)
713 */
714 bool
715 GEOM_Actor
716 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
717                SVTK_SelectionEvent* theSelectionEvent,
718                bool theIsHighlight)
719 {
720 #ifdef MYDEBUG
721   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
722 #endif
723
724   if ( !GetPickable() )
725     return false;  
726
727   myPreHighlightActor->SetVisibility( false );
728   bool anIsPreselected = myIsPreselected;
729   
730   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
731   bool anIsChanged = (mySelectionMode != aSelectionMode);
732
733   if( !theIsHighlight ) {
734     SetPreSelected( false );
735   }else{
736     switch(aSelectionMode){
737     case ActorSelection : 
738     {
739       if( !mySelector->IsSelected( myIO ) ) {
740         SetPreSelected( true );
741       }
742     }
743     default:
744       break;
745     }
746   }
747
748   mySelectionMode = aSelectionMode;
749   anIsChanged |= (anIsPreselected != myIsPreselected);
750
751   SetVisibility(GetVisibility());
752   return anIsChanged;
753 }
754
755 /*!
756   To process highlight (called from SVTK_InteractorStyle)
757 */
758 bool
759 GEOM_Actor
760 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
761             SVTK_SelectionEvent* theSelectionEvent,
762             bool theIsHighlight)
763 {
764   // define the selection of object
765 #ifdef MYDEBUG
766   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
767 #endif
768   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
769   SetSelected(theIsHighlight);
770   if(theIsHighlight)
771     SetPreSelected(false);
772   
773  
774   return aRet;
775 }
776
777 // Copy the follower's composite 4x4 matrix into the matrix provided.
778 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
779 {
780   double *pos, *vup;
781   double Rx[3], Ry[3], Rz[3], p1[3];
782   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
783   int i;
784   double distance;
785   
786   this->GetOrientation();
787   this->Transform->Push();  
788   this->Transform->PostMultiply();  
789   this->Transform->Identity();
790
791   // apply user defined matrix last if there is one 
792   if (this->UserMatrix)
793     {
794     this->Transform->Concatenate(this->UserMatrix);
795     }
796
797   this->Transform->Translate(-this->Origin[0],
798                              -this->Origin[1],
799                              -this->Origin[2]);
800   // scale
801   this->Transform->Scale(this->Scale[0],
802                          this->Scale[1],
803                          this->Scale[2]);
804   
805   // rotate
806   this->Transform->RotateY(this->Orientation[1]);
807   this->Transform->RotateX(this->Orientation[0]);
808   this->Transform->RotateZ(this->Orientation[2]);
809
810   if (theCam)
811     {
812     // do the rotation
813     // first rotate y 
814     pos = theCam->GetPosition();
815     vup = theCam->GetViewUp();
816
817     if (theCam->GetParallelProjection())
818       {
819       theCam->GetDirectionOfProjection(Rz);
820       }
821     else
822       {
823       distance = sqrt(
824         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
825         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
826         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
827       for (i = 0; i < 3; i++)
828         {
829         Rz[i] = (pos[i] - this->Position[i])/distance;
830         }
831       }
832   
833     vtkMath::Cross(vup,Rz,Rx);
834     vtkMath::Normalize(Rx);
835     vtkMath::Cross(Rz,Rx,Ry);
836     
837     matrix->Element[0][0] = Rx[0];
838     matrix->Element[1][0] = Rx[1];
839     matrix->Element[2][0] = Rx[2];
840     matrix->Element[0][1] = Ry[0];
841     matrix->Element[1][1] = Ry[1];
842     matrix->Element[2][1] = Ry[2];
843     matrix->Element[0][2] = Rz[0];
844     matrix->Element[1][2] = Rz[1];
845     matrix->Element[2][2] = Rz[2];
846     
847     this->Transform->Concatenate(matrix);
848     }
849   
850   // translate to projection reference point PRP
851   // this is the camera's position blasted through
852   // the current matrix
853   p1[0] = this->Origin[0] + this->Position[0];
854   p1[1] = this->Origin[1] + this->Position[1];
855   p1[2] = this->Origin[2] + this->Position[2];
856
857   this->Transform->Translate(p1[0],p1[1],p1[2]);
858   this->Transform->GetMatrix(result);
859   
860   matrix->Delete();
861   this->Transform->Pop();  
862 }