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