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