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