]> SALOME platform Git repositories - modules/geom.git/blob - src/OBJECT/GEOM_Actor.cxx
Salome HOME
Mantis issue 0021465: EDF 2067 GEOM: Extrusion along a path leads to a self-intersect...
[modules/geom.git] / src / OBJECT / GEOM_Actor.cxx
1 // Copyright (C) 2007-2011  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 "GEOM_PainterPolyDataMapper.h"
41 #include "SVTK_Actor.h"
42
43 #include <OCC2VTK_Tools.h>
44
45 #include <vtkObjectFactory.h> 
46 #include <vtkRenderer.h> 
47 #include <vtkProperty.h> 
48 #include <vtkPointPicker.h>
49 #include <vtkCellPicker.h>
50  
51 #include <TopAbs_ShapeEnum.hxx>
52 #include <TopExp_Explorer.hxx>
53 #include <TopoDS.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopExp.hxx>
56  
57 #include <vtkPolyDataWriter.h> 
58  
59 #include <vtkAppendPolyData.h>  
60 #include <vtkPolyDataMapper.h>  
61 #include <vtkPolyData.h>  
62 #include <vtkTransform.h>
63 #include <vtkMatrix4x4.h>
64 #include <vtkMath.h>
65 #include <vtkCamera.h>
66
67 #include "utilities.h"
68
69 #include "SALOME_InteractiveObject.hxx"
70
71 //vtkStandardNewMacro(GEOM_Actor);
72
73 #ifndef MYDEBUG
74 //#define MYDEBUG
75 #endif
76
77 GEOM_Actor::GEOM_Actor(): 
78   isOnlyVertex(false),
79
80   myDeflection(-1),
81   myIsForced(false),
82
83   //  myDisplayMode(eWireframe), 
84   myIsSelected(false), 
85   myVectorMode(false),
86
87   myVertexActor(GEOM_DeviceActor::New(),true), 
88   myVertexSource(GEOM_VertexSource::New(),true), 
89  
90   myIsolatedEdgeActor(GEOM_DeviceActor::New(),true), 
91   myIsolatedEdgeSource(GEOM_EdgeSource::New(),true), 
92  
93   myOneFaceEdgeActor(GEOM_DeviceActor::New(),true), 
94   myOneFaceEdgeSource(GEOM_EdgeSource::New(),true), 
95  
96   mySharedEdgeActor(GEOM_DeviceActor::New(),true), 
97   mySharedEdgeSource(GEOM_EdgeSource::New(),true), 
98  
99   myWireframeFaceActor(GEOM_DeviceActor::New(),true), 
100   myWireframeFaceSource(GEOM_WireframeFace::New(),true), 
101  
102   myShadingFaceActor(GEOM_DeviceActor::New(),true), 
103   myShadingFaceSource(GEOM_ShadingFace::New(),true), 
104  
105   myHighlightActor(GEOM_DeviceActor::New(),true), 
106   myAppendFilter(vtkAppendPolyData::New(),true), 
107   // Use mapper as an instance of GEOM_PainterPolyDataMapper class
108   // to prevent drawing of mappers' content (due to an empty definition
109   // of GEOM_PainterPolyDataMapper::RenderPiece(...)).
110   // !!! Presentation of GEOM_Actor is drawing only with help of actors
111   // defined in this class !!!
112   myPolyDataMapper(GEOM_PainterPolyDataMapper::New(),true),
113
114   myHighlightProp(vtkProperty::New()),
115   myPreHighlightProp(vtkProperty::New()),
116   myShadingFaceProp(vtkProperty::New()),
117   myShadingBackFaceProp(vtkProperty::New())
118
119 #ifdef MYDEBUG
120   MESSAGE (this<< " GEOM_Actor::GEOM_Actor");
121 #endif
122
123   myPolyDataMapper->SetInput(myAppendFilter->GetOutput()); 
124   vtkProperty* aProperty; 
125
126   myHighlightProp->SetAmbient(0.5);
127   myHighlightProp->SetDiffuse(0.3);
128   myHighlightProp->SetSpecular(0.2);
129   myHighlightProp->SetRepresentationToSurface();
130   myHighlightProp->SetAmbientColor(1, 1, 1);
131   myHighlightProp->SetDiffuseColor(1, 1, 1);
132   myHighlightProp->SetSpecularColor(0.5, 0.5, 0.5);
133   myHighlightProp->SetPointSize(SALOME_POINT_SIZE);
134   myHighlightActor->SetProperty(myHighlightProp.GetPointer());
135
136   this->myHighlightActor->SetInput(myAppendFilter->GetOutput(),false);
137
138   myPreHighlightProp->SetColor(0,1,1);
139   myPreHighlightProp->SetPointSize(SALOME_POINT_SIZE+2);
140   myPreHighlightProp->SetLineWidth(SALOME_LINE_WIDTH+1);
141   myPreHighlightProp->SetRepresentationToWireframe();
142
143   myAppendFilter->AddInput(myVertexSource->GetOutput()); 
144   myVertexActor->SetInput(myVertexSource->GetOutput(),false); 
145   aProperty = myVertexActor->GetProperty(); 
146   aProperty->SetRepresentation(VTK_POINTS); 
147   aProperty->SetPointSize(3); 
148   aProperty->SetColor(1, 1, 0);
149  
150   myAppendFilter->AddInput(myIsolatedEdgeSource->GetOutput());
151   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); 
152   aProperty = myIsolatedEdgeActor->GetProperty(); 
153   aProperty->SetRepresentation(VTK_WIREFRAME); 
154   aProperty->SetColor(1, 0, 0);
155  
156   myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
157   myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); 
158   aProperty = myOneFaceEdgeActor->GetProperty(); 
159   aProperty->SetRepresentation(VTK_WIREFRAME); 
160   aProperty->SetColor(0, 1, 0);
161  
162   myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); 
163   mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); 
164   aProperty = mySharedEdgeActor->GetProperty(); 
165   aProperty->SetRepresentation(VTK_WIREFRAME); 
166   aProperty->SetColor(1, 1, 0);
167  
168   myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); 
169   myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); 
170   aProperty = myWireframeFaceActor->GetProperty(); 
171   aProperty->SetRepresentation(VTK_WIREFRAME); 
172   aProperty->SetColor(0.5, 0.5, 0.5);
173
174   myShadingFaceActor->SetInput(myShadingFaceSource->GetOutput(),true); 
175
176   myShadingFaceProp->SetRepresentation(VTKViewer::Representation::Surface); 
177   myShadingFaceProp->SetInterpolationToGouraud(); 
178   myShadingFaceProp->SetAmbient(1.0);
179   myShadingFaceProp->SetDiffuse(1.0);
180   myShadingFaceProp->SetSpecular(0.4);
181   myShadingFaceProp->SetAmbientColor(0.329412, 0.223529, 0.027451);
182   myShadingFaceProp->SetDiffuseColor(0.780392, 0.568627, 0.113725);
183   myShadingFaceProp->SetSpecularColor(0.992157, 0.941176, 0.807843);
184
185   myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
186
187   StoreBoundaryColors();
188
189   myNbIsos[0] = -1;
190   myNbIsos[1] = -1;
191
192   // Toggle display mode 
193   setDisplayMode(0); // WIRE FRAME
194   SetVectorMode(0);  //
195
196  
197  
198 GEOM_Actor::~GEOM_Actor() 
199
200 #ifdef MYDEBUG
201   MESSAGE (this<< " ~GEOM_Actor::GEOM_Actor");
202 #endif
203   myHighlightProp->Delete();
204   myPreHighlightProp->Delete();
205   myShadingFaceProp->Delete();
206   myShadingBackFaceProp->Delete();
207
208  
209 GEOM_Actor*  
210 GEOM_Actor:: 
211 New() 
212
213   GEOM_Actor* anObject = new GEOM_Actor(); 
214   anObject->SetMapper(anObject->myPolyDataMapper.Get()); 
215   return anObject; 
216
217  
218  
219 void Write(vtkPolyData* theDataSet, const char* theFileName){ 
220   vtkPolyDataWriter* aWriter = vtkPolyDataWriter::New(); 
221   MESSAGE ("Write - "<<theFileName<<"' : "<<theDataSet->GetNumberOfPoints()<<"; "<<theDataSet->GetNumberOfCells()); 
222   aWriter->SetInput(theDataSet); 
223   aWriter->SetFileName(theFileName); 
224   //aWriter->Write(); 
225   aWriter->Delete(); 
226
227  
228 void 
229 GEOM_Actor:: 
230 SetModified() 
231
232   this->myVertexSource->Modified(); 
233   this->myIsolatedEdgeSource->Modified(); 
234   this->myOneFaceEdgeSource->Modified(); 
235   this->mySharedEdgeSource->Modified(); 
236   this->myWireframeFaceSource->Modified(); 
237   this->myShadingFaceSource->Modified(); 
238
239
240 void  
241 GEOM_Actor:: 
242 SetMapper(vtkMapper* theMapper) 
243
244   SALOME_Actor::SetMapper(theMapper); 
245
246
247 void 
248 GEOM_Actor:: 
249 AddToRender(vtkRenderer* theRenderer)
250 {
251   //SALOME_Actor::AddToRender(theRenderer);
252   
253   theRenderer->AddActor(this); 
254  
255   this->myHighlightActor->AddToRender(theRenderer); 
256   
257
258   myShadingFaceActor->AddToRender(theRenderer); 
259   myWireframeFaceActor->AddToRender(theRenderer); 
260  
261   mySharedEdgeActor->AddToRender(theRenderer); 
262   myOneFaceEdgeActor->AddToRender(theRenderer); 
263   myIsolatedEdgeActor->AddToRender(theRenderer); 
264  
265   myVertexActor->AddToRender(theRenderer); 
266 }
267  
268 void 
269 GEOM_Actor:: 
270 RemoveFromRender(vtkRenderer* theRenderer)
271 {
272   //SALOME_Actor::RemoveFromRender(theRenderer);
273
274   
275   theRenderer->RemoveActor(this);
276
277   myHighlightActor->RemoveFromRender(theRenderer); 
278   myShadingFaceActor->RemoveFromRender(theRenderer); 
279   myWireframeFaceActor->RemoveFromRender(theRenderer); 
280  
281   mySharedEdgeActor->RemoveFromRender(theRenderer); 
282   myOneFaceEdgeActor->RemoveFromRender(theRenderer); 
283   myIsolatedEdgeActor->RemoveFromRender(theRenderer); 
284  
285   myVertexActor->RemoveFromRender(theRenderer);
286
287   
288   SetSelected(false);
289   SetVisibility(false);
290 }
291
292 void  
293 GEOM_Actor:: 
294 setDisplayMode(int theMode) 
295
296 #ifdef MYDEBUG
297   MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
298 #endif
299   
300   if ( theMode == (int)eWireframe ) {
301     RestoreIsoNumbers();
302     // Restore wireframe edges colors
303     RestoreBoundaryColors();
304   }
305   else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
306     // Temporary store number of iso lines in order to recover its later 
307     // when display mode is achnged to 'Wirefame' or 'Shading'.
308     // Iso lines are not displayed in 'Shading with edges' mode.
309     StoreIsoNumbers();
310
311     // Reset number of iso lines to 0
312     ResetIsoNumbers();
313
314     if ( theMode == (int)eShadingWithEdges ) {
315       // Store wireframe edges colors
316       StoreBoundaryColors();
317
318       // Coloring edges
319       myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
320                                                    myEdgesInShadingColor[1],
321                                                    myEdgesInShadingColor[2]);
322       myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
323                                                   myEdgesInShadingColor[1],
324                                                   myEdgesInShadingColor[2]);
325       mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
326                                                  myEdgesInShadingColor[1],
327                                                  myEdgesInShadingColor[2]);
328       //SetModified();
329     } else {
330       myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
331                                                    myEdgesInWireframeColor[1],
332                                                    myEdgesInWireframeColor[2]);
333     }
334   }
335
336   VTKViewer_Actor::setDisplayMode(theMode);
337   SetVisibility(GetVisibility()); 
338
339
340 void  
341 GEOM_Actor:: 
342 SetSelected(bool theIsSelected) 
343
344 #ifdef MYDEBUG
345   MESSAGE ( "GEOM_Actor::SetSelected = "<<theIsSelected  );
346 #endif
347
348   myIsSelected = theIsSelected; 
349   SetVisibility(GetVisibility()); 
350
351
352 void  
353 GEOM_Actor:: 
354 SetVisibility(int theVisibility) 
355
356 #ifdef MYDEBUG
357   MESSAGE ( "GEOM_Actor::SetVisibility = "<<theVisibility <<"  myIsSelected="<< myIsSelected
358             << " theVisibility="<<theVisibility<<" myIsPreselected="<<myIsPreselected );
359 #endif
360
361   SALOME_Actor::SetVisibility(theVisibility);
362
363   this->myHighlightActor->SetVisibility(theVisibility && (myIsSelected || myIsPreselected));
364   
365   myShadingFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges) && (!myIsSelected || !myIsPreselected)); 
366   myWireframeFaceActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe) && !myIsSelected);
367
368   mySharedEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
369   myOneFaceEdgeActor->SetVisibility(theVisibility && (myDisplayMode == (int)eWireframe || myDisplayMode == (int)eShadingWithEdges) && !myIsSelected);
370   myIsolatedEdgeActor->SetVisibility(theVisibility && !myIsSelected);
371
372   myVertexActor->SetVisibility(theVisibility && myDisplayMode == (int)eWireframe && !myIsSelected);// must be added new mode points
373 }
374  
375
376 void
377 GEOM_Actor
378 ::SetNbIsos(const int theNb[2])
379 {
380   myWireframeFaceSource->SetNbIso(theNb);
381 }
382
383 void
384 GEOM_Actor
385 ::GetNbIsos(int &theNbU,int &theNbV)
386 {
387   myWireframeFaceSource->GetNbIso(theNbU, theNbV);
388 }
389
390 void
391 GEOM_Actor
392 ::SetVectorMode(bool theMode)
393 {
394   myVectorMode = theMode;
395   myIsolatedEdgeSource->SetVectorMode(theMode);
396   myOneFaceEdgeSource->SetVectorMode(theMode);
397   mySharedEdgeSource->SetVectorMode(theMode);
398   SetModified();
399 }
400
401 bool
402 GEOM_Actor
403 ::GetVectorMode()
404 {
405   return myVectorMode;
406 }
407
408 void  
409 GEOM_Actor:: 
410 SetDeflection(float theDeflection) 
411
412   if( myDeflection == theDeflection ) 
413     return;
414     
415   myDeflection = theDeflection; 
416  
417   GEOM::MeshShape(myShape,myDeflection);
418   
419   SetModified(); 
420 }
421
422 void GEOM_Actor::SetShape (const TopoDS_Shape& theShape,
423                            float theDeflection,
424                            bool theIsVector)
425 {
426   myShape = theShape;
427
428   myVertexSource->Clear();
429   myIsolatedEdgeSource->Clear();
430   myOneFaceEdgeSource->Clear();
431   mySharedEdgeSource->Clear();
432   myWireframeFaceSource->Clear();
433   myShadingFaceSource->Clear();
434
435   TopExp_Explorer aVertexExp (theShape,TopAbs_VERTEX);
436   for (; aVertexExp.More(); aVertexExp.Next())
437   {
438      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aVertexExp.Current());
439      myVertexSource->AddVertex(aVertex);
440   }
441   
442   SetDeflection(theDeflection);
443
444   // look if edges are free or shared
445   TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
446   TopExp::MapShapesAndAncestors(theShape,TopAbs_EDGE,TopAbs_FACE,anEdgeMap);
447   
448   GEOM::SetShape(theShape,anEdgeMap,theIsVector,
449                  myIsolatedEdgeSource.Get(),
450                  myOneFaceEdgeSource.Get(),
451                  mySharedEdgeSource.Get(),
452                  myWireframeFaceSource.Get(),
453                  myShadingFaceSource.Get());
454   isOnlyVertex =  
455     myIsolatedEdgeSource->IsEmpty() &&
456     myOneFaceEdgeSource->IsEmpty() &&
457     mySharedEdgeSource->IsEmpty() &&
458     myWireframeFaceSource->IsEmpty() &&
459     myShadingFaceSource->IsEmpty();
460
461   
462   if((bool)myShape.Infinite() || isOnlyVertex ){
463     myVertexActor->GetDeviceActor()->SetInfinitive(true);
464     myHighlightActor->GetDeviceActor()->SetInfinitive(true);
465   }
466 }
467
468 // OLD METHODS
469 void GEOM_Actor::setDeflection(double adef) {
470 #ifdef MYDEBUG
471   MESSAGE ( "GEOM_Actor::setDeflection" );
472 #endif
473   SetDeflection((float)adef);
474 }
475
476
477 // warning! must be checked!
478 // SetHighlightProperty
479 // SetWireframeProperty
480 // SetShadingProperty
481
482 void GEOM_Actor::SetHighlightProperty(vtkProperty* Prop)
483 {
484 #ifdef MYDEBUG
485   MESSAGE ( "GEOM_Actor::SetHighlightProperty" );
486 #endif
487   this->myHighlightActor->GetProperty()->DeepCopy(Prop);
488   
489 }
490
491 void GEOM_Actor::SetWireframeProperty(vtkProperty* Prop)
492 {
493 #ifdef MYDEBUG
494   MESSAGE ( this << " GEOM_Actor::SetWireframeProperty" );
495 #endif
496   // must be filled
497   myWireframeFaceActor->SetProperty(Prop);
498 }
499
500 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
501 {
502 #ifdef MYDEBUG
503   MESSAGE ( "GEOM_Actor::SetShadingProperty" );
504 #endif
505   myShadingFaceProp->DeepCopy(Prop);
506 }
507
508
509 void GEOM_Actor::Render(vtkRenderer *ren, vtkMapper *theMapper)
510 {
511 #ifdef MYDEBUG
512   MESSAGE ( "GEOM_Actor::Render" );
513 #endif
514
515   if(!GetVisibility())
516     return;
517
518   /* render the property */
519   if (!this->Property) {
520     // force creation of a property
521     this->GetProperty();
522     this->Property->SetInterpolation(1);
523     this->Property->SetRepresentationToSurface();
524     this->Property->SetAmbient(0.3);
525     this->Property->SetAmbientColor(0.88,0.86,0.2);
526     this->Property->SetDiffuseColor(0.99,0.7,0.21);
527     this->Property->SetSpecularColor(0.99,0.98,0.83);
528   }
529
530   switch(myDisplayMode){
531   case eWireframe://wireframe
532     myPreHighlightProp->SetRepresentationToWireframe();
533     myHighlightProp->SetRepresentationToWireframe();
534     break;
535   case eShading://shading
536   case eShadingWithEdges://shading with edges
537     myPreHighlightProp->SetRepresentationToSurface();
538     myHighlightProp->SetRepresentationToSurface();
539     break;
540   }
541
542   if(!myIsSelected){
543     if(myIsPreselected){
544       this->myHighlightActor->SetProperty(myPreHighlightProp.GetPointer());
545       myShadingFaceActor->SetProperty(myPreHighlightProp.GetPointer());
546       myShadingFaceActor->SetBackfaceProperty(myPreHighlightProp.GetPointer());
547     } else {
548       this->myHighlightActor->SetProperty(myShadingFaceProp.GetPointer());
549       myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
550       myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
551     }
552   }
553   else{
554     this->myHighlightActor->SetProperty(myHighlightProp.GetPointer());
555     myShadingFaceActor->SetProperty(myHighlightProp.GetPointer());
556     myShadingFaceActor->SetBackfaceProperty(myHighlightProp.GetPointer());
557   }
558
559   this->Property->Render(this, ren);
560   if (this->BackfaceProperty) {
561     this->BackfaceProperty->BackfaceRender(this, ren);
562     this->Device->SetBackfaceProperty(this->BackfaceProperty);
563   }
564   this->Device->SetProperty(this->Property);
565   /*  if(myShape.ShapeType() == TopAbs_VERTEX) {
566     if(ren){
567       //The parameter determine size of vertex actor relate to diagonal of RendererWindow
568       static vtkFloatingPointType delta = 0.01;
569       vtkFloatingPointType X1 = -1, Y1 = -1, Z1 = 0;
570       ren->ViewToWorld(X1,Y1,Z1);
571       vtkFloatingPointType X2 = +1, Y2 = +1, Z2 = 0;
572       ren->ViewToWorld(X2,Y2,Z2);
573       Z2 = sqrt((X2-X1)*(X2-X1) + (Y2-Y1)*(Y2-Y1) + (Z2-Z1)*(Z2-Z1));
574       this->SetScale(Z2*delta);
575     }
576     vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New();
577     this->GetMatrix(ren->GetActiveCamera(), aMatrix);
578     this->Device->SetUserMatrix(aMatrix);
579     this->Device->Render(ren,theMapper);
580     aMatrix->Delete();    
581     } else*/
582     this->Device->Render(ren, theMapper);
583 }
584
585 void GEOM_Actor::ReleaseGraphicsResources(vtkWindow *)
586 {
587 #ifdef MYDEBUG
588   MESSAGE ( "GEOM_Actor::ReleaseGraphicsResources" );
589 #endif  
590 }
591
592
593
594 void GEOM_Actor::ShallowCopy(vtkProp *prop)
595 {
596 #ifdef MYDEBUG
597   MESSAGE ( "GEOM_Actor::ShallowCopy" );
598 #endif
599   GEOM_Actor *f = GEOM_Actor::SafeDownCast(prop);
600   if ( f != NULL )
601     {
602       this->SetShape(f->getTopo(),f->GetDeflection());
603     }
604
605   // Now do superclass
606   this->SALOME_Actor::ShallowCopy(prop);
607 }
608
609 const TopoDS_Shape& GEOM_Actor::getTopo() {
610 #ifdef MYDEBUG
611   MESSAGE ( "GEOM_Actor::getTopo" );
612 #endif
613   return myShape;
614 }
615
616 void GEOM_Actor::setInputShape(const TopoDS_Shape& ashape, double adef1,
617                                int imode, bool isVector)
618 {
619 #ifdef MYDEBUG
620   MESSAGE ( "GEOM_Actor::setInputShape" );
621 #endif
622 }
623
624 double GEOM_Actor::getDeflection()
625 {
626 #ifdef MYDEBUG
627   MESSAGE ( "GEOM_Actor::getDeflection" );
628 #endif
629   return (double) GetDeflection();
630 }
631
632
633 double GEOM_Actor::isVector()
634 {
635 #ifdef MYDEBUG
636   MESSAGE ( "GEOM_Actor::isVector" );
637 #endif  
638   return 0;
639 }
640
641 void GEOM_Actor::SubShapeOn()
642 {
643 #ifdef MYDEBUG
644   MESSAGE ( "GEOM_Actor::SubShapeOn" );
645 #endif  
646 }
647
648 void GEOM_Actor::SubShapeOff()
649 {
650 #ifdef MYDEBUG
651   MESSAGE ( "GEOM_Actor::SubShapeOff" );
652 #endif
653 }
654
655 void GEOM_Actor::highlight(bool highlight)
656 {
657 #ifdef MYDEBUG
658   MESSAGE ( this << " GEOM_Actor::highlight highlight="<<highlight );
659 #endif
660   SALOME_Actor::highlight(highlight);  
661 }
662
663 void GEOM_Actor::SetOpacity(vtkFloatingPointType opa)
664 {
665   // enk:tested OK
666   myShadingFaceProp->SetOpacity(opa);
667   myShadingBackFaceProp->SetOpacity(opa);
668   myHighlightProp->SetOpacity(opa);
669   myPreHighlightProp->SetOpacity(opa);
670   myVertexActor->GetProperty()->SetOpacity(opa);
671 }
672
673 vtkFloatingPointType GEOM_Actor::GetOpacity()
674 {
675   // enk:tested OK
676   return myShadingFaceProp->GetOpacity(); 
677 }
678
679 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
680 {
681   // enk:tested OK
682   myShadingFaceProp->SetColor(r,g,b);                          // shading color (Shading)
683   myShadingBackFaceProp->SetColor(r,g,b);                      // back face shading color (Shading)
684   myVertexActor->GetProperty()->SetColor(r,g,b);               // vertex actor (Shading/Wireframe)
685   if ( myDisplayMode != (int)eShadingWithEdges ) {
686     myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b);         // standalone edge color (Wireframe)
687     myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b);          // standalone face edge color (Wireframe)
688     mySharedEdgeActor->GetProperty()->SetColor(r,g,b);           // share edge color (Wireframe)
689   }
690
691   StoreBoundaryColors();
692 }
693
694 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
695 {
696   // enk:tested OK
697   vtkFloatingPointType aRGB[3];
698   myShadingFaceProp->GetColor(aRGB);
699   r = aRGB[0];
700   g = aRGB[1];
701   b = aRGB[2];
702 }
703
704 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
705 {
706   int aSize = theProps.size();
707
708   if ( aSize < 1 || aSize > 2)
709     return;
710
711   // theProps[0] -- front material properties
712   // theProps[1] -- back material properties (if exist)
713   // If there are no back material properties,
714   // we get front material properties as back material
715
716   double aCoefnt;
717
718   // Set reflection coefficients
719   aCoefnt = theProps[0]->GetAmbient();
720   myShadingFaceProp->SetAmbient(aCoefnt);
721   myVertexActor->GetProperty()->SetAmbient(aCoefnt);
722   if ( aSize == 2 )
723     aCoefnt = theProps[1]->GetAmbient();
724   myShadingBackFaceProp->SetAmbient(aCoefnt);
725
726   // Set diffuse coefficients
727   aCoefnt = theProps[0]->GetDiffuse();
728   myShadingFaceProp->SetDiffuse(aCoefnt);
729   myVertexActor->GetProperty()->SetDiffuse(aCoefnt);
730   if ( aSize == 2 )
731     aCoefnt = theProps[1]->GetDiffuse();
732   myShadingBackFaceProp->SetDiffuse(aCoefnt);
733   
734   // Set specular coefficients
735   aCoefnt = theProps[0]->GetSpecular();
736   myShadingFaceProp->SetSpecular(aCoefnt);
737   myVertexActor->GetProperty()->SetSpecular(aCoefnt);
738   if ( aSize == 2 )
739     aCoefnt = theProps[1]->GetSpecular();
740   myShadingBackFaceProp->SetSpecular(aCoefnt);
741
742
743   double* aColor;
744
745   // Set reflection colors
746   aColor = theProps[0]->GetAmbientColor();
747   myShadingFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
748   myVertexActor->GetProperty()->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
749   if ( aSize == 2 )
750     aColor = theProps[1]->GetAmbientColor();
751   myShadingBackFaceProp->SetAmbientColor(aColor[0], aColor[1], aColor[2]);
752
753   // Set diffuse colors
754   aColor = theProps[0]->GetDiffuseColor();
755   myShadingFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
756   myVertexActor->GetProperty()->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
757   if ( aSize == 2 )
758     aColor = theProps[1]->GetDiffuseColor();
759   myShadingBackFaceProp->SetDiffuseColor(aColor[0], aColor[1], aColor[2]);
760
761   // Set specular colors
762   aColor = theProps[0]->GetSpecularColor();
763   myShadingFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
764   myVertexActor->GetProperty()->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
765   if ( aSize == 2 )
766     aColor = theProps[1]->GetSpecularColor();
767   myShadingBackFaceProp->SetSpecularColor(aColor[0], aColor[1], aColor[2]);
768
769   // Set shininess
770   aCoefnt = theProps[0]->GetSpecularPower();
771   myShadingFaceProp->SetSpecularPower(aCoefnt);
772   myVertexActor->GetProperty()->SetSpecularPower(aCoefnt);
773   if ( aSize == 2 )
774     aCoefnt = theProps[1]->GetSpecularPower();
775   myShadingBackFaceProp->SetSpecularPower(aCoefnt);
776
777   // Set back face material property
778   myShadingFaceActor->SetBackfaceProperty(myShadingBackFaceProp.GetPointer());
779 }
780
781 vtkProperty* GEOM_Actor::GetFrontMaterial()
782 {
783   return myShadingFaceProp;
784 }
785
786 vtkProperty* GEOM_Actor::GetBackMaterial()
787 {
788   return myShadingBackFaceProp;
789 }
790
791 bool GEOM_Actor::IsInfinitive()
792 {
793   return ((bool)myShape.Infinite() || isOnlyVertex);
794 }
795
796 /*!
797   To map current selection to VTK representation
798 */
799 void
800 GEOM_Actor
801 ::Highlight(bool theIsHighlight)
802 {
803   myIsSelected = theIsHighlight;
804 #ifdef MYDEBUG
805   MESSAGE ( this << " GEOM_Actor::Highlight myIsSelected="<<myIsSelected );
806 #endif
807
808   if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
809     if ( theIsHighlight )
810       RestoreIsoNumbers();
811     else
812       // Reset number of iso lines to 0
813       ResetIsoNumbers();
814   }
815
816   SALOME_Actor::Highlight(theIsHighlight); // this method call ::highlight(theIsHighlight) in the end
817   SetVisibility(GetVisibility());
818 }
819
820 /*!
821   To process prehighlight (called from SVTK_InteractorStyle)
822 */
823 bool
824 GEOM_Actor
825 ::PreHighlight(vtkInteractorStyle *theInteractorStyle, 
826                SVTK_SelectionEvent* theSelectionEvent,
827                bool theIsHighlight)
828 {
829 #ifdef MYDEBUG
830   MESSAGE ( this<<" GEOM_Actor::PreHighlight (3) theIsHighlight="<<theIsHighlight );
831 #endif
832
833   if ( !GetPickable() )
834     return false;  
835
836   if ( myDisplayMode == (int)eShading || myDisplayMode == (int)eShadingWithEdges ) {
837     if ( theIsHighlight )
838       RestoreIsoNumbers();
839     else
840       // Reset number of iso lines to 0
841       ResetIsoNumbers();
842   }
843
844   myPreHighlightActor->SetVisibility( false );
845   bool anIsPreselected = myIsPreselected;
846   
847   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
848   bool anIsChanged = (mySelectionMode != aSelectionMode);
849
850   if( !theIsHighlight ) {
851     SetPreSelected( false );
852   }else{
853     switch(aSelectionMode){
854     case ActorSelection : 
855     {
856 //       cout << "=============== " << myIO->getEntry() << endl;
857 //       int nbio = mySelector->IObjectCount();
858 //       cout << " nbio = " << nbio << endl;
859
860       if( !mySelector->IsSelected( myIO ) ) {
861         //      printf ("!!!!!!!!!!!!!!!!\n");
862         SetPreSelected( true );
863       }
864     }
865     default:
866       break;
867     }
868   }
869
870   mySelectionMode = aSelectionMode;
871   anIsChanged |= (anIsPreselected != myIsPreselected);
872
873   SetVisibility(GetVisibility());
874   return anIsChanged;
875 }
876
877 /*!
878   To process highlight (called from SVTK_InteractorStyle)
879 */
880 bool
881 GEOM_Actor
882 ::Highlight(vtkInteractorStyle *theInteractorStyle, 
883             SVTK_SelectionEvent* theSelectionEvent,
884             bool theIsHighlight)
885 {
886   // define the selection of object
887 #ifdef MYDEBUG
888   MESSAGE ( std::endl << this << " GEOM_Actor::Highlight (3) myIsSelected="<<myIsSelected );
889 #endif
890   bool aRet = SALOME_Actor::Highlight(theInteractorStyle,theSelectionEvent,theIsHighlight);
891   SetSelected(theIsHighlight);
892   if(theIsHighlight)
893     SetPreSelected(false);
894   
895  
896   return aRet;
897 }
898
899 // Copy the follower's composite 4x4 matrix into the matrix provided.
900 void GEOM_Actor::GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result)
901 {
902   double *pos, *vup;
903   double Rx[3], Ry[3], Rz[3], p1[3];
904   vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
905   int i;
906   double distance;
907   
908   this->GetOrientation();
909   this->Transform->Push();  
910   this->Transform->PostMultiply();  
911   this->Transform->Identity();
912
913   // apply user defined matrix last if there is one 
914   if (this->UserMatrix)
915     {
916     this->Transform->Concatenate(this->UserMatrix);
917     }
918
919   this->Transform->Translate(-this->Origin[0],
920                              -this->Origin[1],
921                              -this->Origin[2]);
922   // scale
923   this->Transform->Scale(this->Scale[0],
924                          this->Scale[1],
925                          this->Scale[2]);
926   
927   // rotate
928   this->Transform->RotateY(this->Orientation[1]);
929   this->Transform->RotateX(this->Orientation[0]);
930   this->Transform->RotateZ(this->Orientation[2]);
931
932   if (theCam)
933     {
934     // do the rotation
935     // first rotate y 
936     pos = theCam->GetPosition();
937     vup = theCam->GetViewUp();
938
939     if (theCam->GetParallelProjection())
940       {
941       theCam->GetDirectionOfProjection(Rz);
942       }
943     else
944       {
945       distance = sqrt(
946         (pos[0] - this->Position[0])*(pos[0] - this->Position[0]) +
947         (pos[1] - this->Position[1])*(pos[1] - this->Position[1]) +
948         (pos[2] - this->Position[2])*(pos[2] - this->Position[2]));
949       for (i = 0; i < 3; i++)
950         {
951         Rz[i] = (pos[i] - this->Position[i])/distance;
952         }
953       }
954   
955     vtkMath::Cross(vup,Rz,Rx);
956     vtkMath::Normalize(Rx);
957     vtkMath::Cross(Rz,Rx,Ry);
958     
959     matrix->Element[0][0] = Rx[0];
960     matrix->Element[1][0] = Rx[1];
961     matrix->Element[2][0] = Rx[2];
962     matrix->Element[0][1] = Ry[0];
963     matrix->Element[1][1] = Ry[1];
964     matrix->Element[2][1] = Ry[2];
965     matrix->Element[0][2] = Rz[0];
966     matrix->Element[1][2] = Rz[1];
967     matrix->Element[2][2] = Rz[2];
968     
969     this->Transform->Concatenate(matrix);
970     }
971   
972   // translate to projection reference point PRP
973   // this is the camera's position blasted through
974   // the current matrix
975   p1[0] = this->Origin[0] + this->Position[0];
976   p1[1] = this->Origin[1] + this->Position[1];
977   p1[2] = this->Origin[2] + this->Position[2];
978
979   this->Transform->Translate(p1[0],p1[1],p1[2]);
980   this->Transform->GetMatrix(result);
981   
982   matrix->Delete();
983   this->Transform->Pop();  
984 }  
985
986 void GEOM_Actor::SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
987 {
988   myEdgesInShadingColor[0] = r;
989   myEdgesInShadingColor[1] = g;
990   myEdgesInShadingColor[2] = b;
991 }
992
993 void GEOM_Actor::StoreIsoNumbers()
994 {  
995   myWireframeFaceSource->GetNbIso(myNbIsos[0], myNbIsos[1]);
996 }
997
998 void GEOM_Actor::RestoreIsoNumbers()
999 {
1000   if ( myNbIsos[0] > 0 || myNbIsos[1] > 0 )
1001     // Restore number of U and (or) V iso lines
1002     myWireframeFaceSource->SetNbIso(myNbIsos);
1003 }
1004   
1005 void GEOM_Actor::ResetIsoNumbers()
1006 {
1007   int aNb[2] = {0, 0};
1008   myWireframeFaceSource->SetNbIso(aNb);
1009 }
1010
1011 void GEOM_Actor::StoreBoundaryColors()
1012 {
1013   myShadingFaceProp->GetColor(myEdgesInWireframeColor);
1014
1015 }
1016  
1017 void GEOM_Actor::RestoreBoundaryColors()
1018 {
1019   myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1020                                                myEdgesInWireframeColor[1],
1021                                                myEdgesInWireframeColor[2]);
1022   myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1023                                               myEdgesInWireframeColor[1],
1024                                               myEdgesInWireframeColor[2]);
1025   mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
1026                                              myEdgesInWireframeColor[1],
1027                                              myEdgesInWireframeColor[2]);
1028 }