]> SALOME platform Git repositories - modules/geom.git/blob - src/OBJECT/GEOM_Actor.cxx
Salome HOME
Merge from V5_1_main branch 24/11/2010
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
1 //  Copyright (C) 2007-2010  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
23 //  GEOM OBJECT : interactive object for Geometry entities visualization
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 <OCC2VTK_Tools.h>
43
44 #include <vtkObjectFactory.h> 
45 #include <vtkRenderer.h> 
46 #include <vtkProperty.h> 
47 #include <vtkPointPicker.h>
48 #include <vtkCellPicker.h>
49  
50 #include <TopAbs_ShapeEnum.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopoDS.hxx>
53 #include <BRep_Tool.hxx>
54 #include <TopExp.hxx>
55  
56 #include <vtkPolyDataWriter.h> 
57  
58 #include <vtkAppendPolyData.h>  
59 #include <vtkPolyDataMapper.h>  
60 #include <vtkPolyData.h>  
61 #include <vtkTransform.h>
62 #include <vtkMatrix4x4.h>
63 #include <vtkMath.h>
64 #include <vtkCamera.h>
65
66 #include "utilities.h"
67
68 #include "SALOME_InteractiveObject.hxx"
69
70 //vtkStandardNewMacro(GEOM_Actor);
71
72 #ifndef MYDEBUG
73 //#define MYDEBUG
74 #endif
75
76 GEOM_Actor::GEOM_Actor(): 
77   //  myDisplayMode(eWireframe), 
78   myIsSelected(false), 
79   myVectorMode(false),
80   myVertexActor(GEOM_DeviceActor::New(),true), 
81   myVertexSource(GEOM_VertexSource::New(),true), 
82  
83   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
84   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
85  
86   myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), 
87   myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), 
88  
89   mySharedEdgeActor(GEOM_DeviceActor::New(),true), 
90   mySharedEdgeSource(GEOM_EdgeSource::New(),true), 
91  
92   myWireframeFaceActor(GEOM_DeviceActor::New(),true), 
93   myWireframeFaceSource(GEOM_WireframeFace::New(),true), 
94  
95   myShadingFaceActor(GEOM_DeviceActor::New(),true), 
96   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
97  
98   myHighlightActor(GEOM_DeviceActor::New(),true), 
99   myAppendFilter(vtkAppendPolyData::New(),true), 
100   myPolyDataMapper(vtkPolyDataMapper::New(),true),
101
102   myHighlightProp(vtkProperty::New()),
103   myPreHighlightProp(vtkProperty::New()),
104   myShadingFaceProp(vtkProperty::New()),
105   isOnlyVertex(false)
106
107 #ifdef MYDEBUG
108   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
109 #endif
110
111   myPolyDataMapper->SetInput(myAppendFilter->GetOutput()); 
112   vtkProperty* aProperty; 
113
114   myHighlightProp->SetAmbient(0.5);
115   myHighlightProp->SetDiffuse(0.3);
116   myHighlightProp->SetSpecular(0.2);
117   myHighlightProp->SetRepresentationToSurface();
118   myHighlightProp->SetAmbientColor(1, 1, 1);
119   myHighlightProp->SetDiffuseColor(1, 1, 1);
120   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
121   myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
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(theVisibility && !myIsSelected);// must be added new mode points 
318 }
319  
320
321 void
322 GEOM_Actor
323 ::SetNbIsos(const int theNb[2])
324 {
325   myWireframeFaceSource->SetNbIso(theNb);
326 }
327
328 void
329 GEOM_Actor
330 ::GetNbIsos(int &theNbU,int &theNbV)
331 {
332   myWireframeFaceSource->GetNbIso(theNbU, theNbV);
333 }
334
335 void
336 GEOM_Actor
337 ::SetVectorMode(bool theMode)
338 {
339   myVectorMode = theMode;
340   myIsolatedEdgeSource->SetVectorMode(theMode);
341   myOneFaceEdgeSource->SetVectorMode(theMode);
342   mySharedEdgeSource->SetVectorMode(theMode);
343   SetModified();
344 }
345
346 bool
347 GEOM_Actor
348 ::GetVectorMode()
349 {
350   return myVectorMode;
351 }
352
353 void  
354 GEOM_Actor:: 
355 SetDeflection(float theDeflection, bool theIsRelative) 
356
357   myDeflection = theDeflection; 
358   myIsRelative = theIsRelative; 
359  
360   GEOM::MeshShape2(myShape,myDeflection,myIsRelative); 
361  
362   SetModified(); 
363
364
365 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
366                            float theDeflection,
367                            bool theIsRelative,
368                            bool theIsVector)
369 {
370   myShape = theShape;
371
372   myVertexSource->Clear();
373   myIsolatedEdgeSource->Clear();
374   myOneFaceEdgeSource->Clear();
375   mySharedEdgeSource->Clear();
376   myWireframeFaceSource->Clear();
377   myShadingFaceSource->Clear();
378
379   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
380   for (; aVertexExp.More(); aVertexExp.Next())
381   {
382      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
383      myVertexSource->AddVertex(aVertex);
384   }
385   SetDeflection(theDeflection, theIsRelative);
386
387   // look if edges are free or shared
388   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
389   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
390   
391   GEOM::SetShape(theShape,anEdgeMap,theIsVector,
392                  myIsolatedEdgeSource.Get(),
393                  myOneFaceEdgeSource.Get(),
394                  mySharedEdgeSource.Get(),
395                  myWireframeFaceSource.Get(),
396                  myShadingFaceSource.Get());
397   isOnlyVertex =  
398     myIsolatedEdgeSource->IsEmpty() &&
399     myOneFaceEdgeSource->IsEmpty() &&
400     mySharedEdgeSource->IsEmpty() &&
401     myWireframeFaceSource->IsEmpty() &&
402     myShadingFaceSource->IsEmpty();
403
404   
405   if((bool)myShape.Infinite() || isOnlyVertex ){
406     myVertexActor->GetDeviceActor()->SetInfinitive(true);
407     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
408   }
409 }
410
411 // OLD METHODS
412 void GEOM_Actor::setDeflection(double adef) {
413 #ifdef MYDEBUG
414   MESSAGE ( "GEOM_Actor::setDeflection" );
415 #endif
416   SetDeflection((float)adef,GetIsRelative());
417 }
418
419
420 // warning! must be checked!
421 // SetHighlightProperty
422 // SetWireframeProperty
423 // SetShadingProperty
424
425 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
426 {
427 #ifdef MYDEBUG
428   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
429 #endif
430   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
431   
432 }
433
434 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
435 {
436 #ifdef MYDEBUG
437   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
438 #endif
439   // must be filled
440   myWireframeFaceActor->SetProperty(Prop);
441 }
442
443 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
444 {
445 #ifdef MYDEBUG
446   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
447 #endif
448   myShadingFaceProp->DeepCopy(Prop);
449 }
450
451
452 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
453 {
454 #ifdef MYDEBUG
455   MESSAGE ( "GEOM_Actor::Render" );
456 #endif
457
458   if(!GetVisibility())
459     return;
460
461   /* render the property */
462   if (!this->Property) {
463     // force creation of a property
464     this->GetProperty();
465     this->Property->SetInterpolation(1);
466     this->Property->SetRepresentationToSurface();
467     this->Property->SetAmbient(0.3);
468     this->Property->SetAmbientColor(0.88,0.86,0.2);
469     this->Property->SetDiffuseColor(0.99,0.7,0.21);
470     this->Property->SetSpecularColor(0.99,0.98,0.83);
471   }
472
473   switch(myDisplayMode){
474   case 0://wireframe
475     myPreHighlightProp->SetRepresentationToWireframe();
476     myHighlightProp->SetRepresentationToWireframe();
477     break;
478   case 1://shading
479     myPreHighlightProp->SetRepresentationToSurface();
480     myHighlightProp->SetRepresentationToSurface();
481     break;
482   }
483
484   if(!myIsSelected){
485     if(myIsPreselected){
486       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
487       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
488     } else {
489       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
490       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
491     }
492   }
493   else{
494     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
495     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
496   }
497
498   this->Property->Render(this, ren);
499   if (this->BackfaceProperty) {
500     this->BackfaceProperty->BackfaceRender(this, ren);
501     this->Device->SetBackfaceProperty(this->BackfaceProperty);
502   }
503   this->Device->SetProperty(this->Property);
504   /*  if(myShape.ShapeType() == TopAbs_VERTEX) {
505     if(ren){
506       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
507       static vtkFloatingPointType delta = 0.01;
508       vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
509       ren->ViewToWorld(X1,Y1,Z1);
510       vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
511       ren->ViewToWorld(X2,Y2,Z2);
512       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
513       this->SetScale(Z2*delta);
514     }
515     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
516     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
517     this->Device->SetUserMatrix(aMatrix);
518     this->Device->Render(ren,theMapper);
519     aMatrix->Delete();    
520     } else*/
521     this->Device->Render(ren, theMapper);
522 }
523
524 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
525 {
526 #ifdef MYDEBUG
527   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
528 #endif  
529 }
530
531
532
533 void GEOM_Actor::ShallowCopy(vtkProp *prop)
534 {
535 #ifdef MYDEBUG
536   MESSAGE ( "GEOM_Actor::ShallowCopy" );
537 #endif
538   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
539   if ( f != NULL )
540     {
541       this->SetShape(f->getTopo(),f->GetDeflection(),f->GetIsRelative());
542     }
543
544   // Now do superclass
545   this->SALOME_Actor::ShallowCopy(prop);
546 }
547
548 const TopoDS_Shape& GEOM_Actor::getTopo() {
549 #ifdef MYDEBUG
550   MESSAGE ( "GEOM_Actor::getTopo" );
551 #endif
552   return myShape;
553 }
554
555 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
556                                int imode, bool isVector)
557 {
558 #ifdef MYDEBUG
559   MESSAGE ( "GEOM_Actor::setInputShape" );
560 #endif
561 }
562
563 double GEOM_Actor::getDeflection()
564 {
565 #ifdef MYDEBUG
566   MESSAGE ( "GEOM_Actor::getDeflection" );
567 #endif
568   return (double) GetDeflection();
569 }
570
571
572 double GEOM_Actor::isVector()
573 {
574 #ifdef MYDEBUG
575   MESSAGE ( "GEOM_Actor::isVector" );
576 #endif  
577   return 0;
578 }
579
580 void GEOM_Actor::SubShapeOn()
581 {
582 #ifdef MYDEBUG
583   MESSAGE ( "GEOM_Actor::SubShapeOn" );
584 #endif  
585 }
586
587 void GEOM_Actor::SubShapeOff()
588 {
589 #ifdef MYDEBUG
590   MESSAGE ( "GEOM_Actor::SubShapeOff" );
591 #endif
592 }
593
594 void GEOM_Actor::highlight(bool highlight)
595 {
596 #ifdef MYDEBUG
597   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
598 #endif
599   SALOME_Actor::highlight(highlight);
600 }
601
602 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
603 {
604   // enk:tested OK
605   myShadingFaceProp->SetOpacity(opa);
606   myHighlightProp->SetOpacity(opa);
607   myPreHighlightProp->SetOpacity(opa);
608   myVertexActor->GetProperty()->SetOpacity(opa);
609 }
610
611 vtkFloatingPointType GEOM_Actor::GetOpacity()
612 {
613   // enk:tested OK
614   return myShadingFaceProp->GetOpacity(); 
615 }
616
617 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
618 {
619   // enk:tested OK
620   myShadingFaceProp->SetColor(r,g,b);                          // shading color (Shading)
621   myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b);         // standalone edge color (Wireframe)
622   myVertexActor->GetProperty()->SetColor(r,g,b);               // vertex actor (Shading/Wireframe)
623   myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b);          // standalone face edge color (Wireframe)
624   mySharedEdgeActor->GetProperty()->SetColor(r,g,b);           // share edge color (Wireframe)
625 }
626
627 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
628 {
629   // enk:tested OK
630   vtkFloatingPointType aRGB[3];
631   myShadingFaceProp->GetColor(aRGB);
632   r = aRGB[0];
633   g = aRGB[1];
634   b = aRGB[2];
635 }
636
637 bool GEOM_Actor::IsInfinitive()
638 {
639   return ((bool)myShape.Infinite() || isOnlyVertex);
640 }
641
642 /*!
643   To map current selection to VTK representation
644 */
645 void
646 GEOM_Actor
647 ::Highlight(bool theIsHighlight)
648 {
649   myIsSelected = theIsHighlight;
650 #ifdef MYDEBUG
651   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
652 #endif
653   
654   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
655   SetVisibility(GetVisibility());
656 }
657
658 /*!
659   To process prehighlight (called from SVTK_InteractorStyle)
660 */
661 bool
662 GEOM_Actor
663 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
664                SVTK_SelectionEvent* theSelectionEvent,
665                bool theIsHighlight)
666 {
667 #ifdef MYDEBUG
668   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
669 #endif
670
671   if ( !GetPickable() )
672     return false;  
673
674   myPreHighlightActor->SetVisibility( false );
675   bool anIsPreselected = myIsPreselected;
676   
677   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
678   bool anIsChanged = (mySelectionMode != aSelectionMode);
679
680   if( !theIsHighlight ) {
681     SetPreSelected( false );
682   }else{
683     switch(aSelectionMode){
684     case ActorSelection : 
685     {
686       //      cout << "=============== " << myIO->getEntry() << endl;
687       int nbio = mySelector->IObjectCount();
688       //      cout << " nbio = " << nbio << endl;
689
690       if( !mySelector->IsSelected( myIO ) ) {
691         //      printf ("!!!!!!!!!!!!!!!!\n");
692         SetPreSelected( true );
693       }
694     }
695     default:
696       break;
697     }
698   }
699
700   mySelectionMode = aSelectionMode;
701   anIsChanged |= (anIsPreselected != myIsPreselected);
702
703   SetVisibility(GetVisibility());
704   return anIsChanged;
705 }
706
707 /*!
708   To process highlight (called from SVTK_InteractorStyle)
709 */
710 bool
711 GEOM_Actor
712 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
713             SVTK_SelectionEvent* theSelectionEvent,
714             bool theIsHighlight)
715 {
716   // define the selection of object
717 #ifdef MYDEBUG
718   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
719 #endif
720   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
721   SetSelected(theIsHighlight);
722   if(theIsHighlight)
723     SetPreSelected(false);
724   
725  
726   return aRet;
727 }
728
729 // Copy the follower's composite 4x4 matrix into the matrix provided.
730 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
731 {
732   double *pos, *vup;
733   double Rx[3], Ry[3], Rz[3], p1[3];
734   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
735   int i;
736   double distance;
737   
738   this->GetOrientation();
739   this->Transform->Push();  
740   this->Transform->PostMultiply();  
741   this->Transform->Identity();
742
743   // apply user defined matrix last if there is one 
744   if (this->UserMatrix)
745     {
746     this->Transform->Concatenate(this->UserMatrix);
747     }
748
749   this->Transform->Translate(-this->Origin[0],
750                              -this->Origin[1],
751                              -this->Origin[2]);
752   // scale
753   this->Transform->Scale(this->Scale[0],
754                          this->Scale[1],
755                          this->Scale[2]);
756   
757   // rotate
758   this->Transform->RotateY(this->Orientation[1]);
759   this->Transform->RotateX(this->Orientation[0]);
760   this->Transform->RotateZ(this->Orientation[2]);
761
762   if (theCam)
763     {
764     // do the rotation
765     // first rotate y 
766     pos = theCam->GetPosition();
767     vup = theCam->GetViewUp();
768
769     if (theCam->GetParallelProjection())
770       {
771       theCam->GetDirectionOfProjection(Rz);
772       }
773     else
774       {
775       distance = sqrt(
776         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
777         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
778         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
779       for (i = 0; i < 3; i++)
780         {
781         Rz[i] = (pos[i] - this->Position[i])/distance;
782         }
783       }
784   
785     vtkMath::Cross(vup,Rz,Rx);
786     vtkMath::Normalize(Rx);
787     vtkMath::Cross(Rz,Rx,Ry);
788     
789     matrix->Element[0][0] = Rx[0];
790     matrix->Element[1][0] = Rx[1];
791     matrix->Element[2][0] = Rx[2];
792     matrix->Element[0][1] = Ry[0];
793     matrix->Element[1][1] = Ry[1];
794     matrix->Element[2][1] = Ry[2];
795     matrix->Element[0][2] = Rz[0];
796     matrix->Element[1][2] = Rz[1];
797     matrix->Element[2][2] = Rz[2];
798     
799     this->Transform->Concatenate(matrix);
800     }
801   
802   // translate to projection reference point PRP
803   // this is the camera's position blasted through
804   // the current matrix
805   p1[0] = this->Origin[0] + this->Position[0];
806   p1[1] = this->Origin[1] + this->Position[1];
807   p1[2] = this->Origin[2] + this->Position[2];
808
809   this->Transform->Translate(p1[0],p1[1],p1[2]);
810   this->Transform->GetMatrix(result);
811   
812   matrix->Delete();
813   this->Transform->Pop();  
814 }