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