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