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