Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / OBJECT / VISU_GaussPtsAct.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VISU_MeshAct.hxx
25 //  Author : Laurent CORNABE with the help of Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 #include "VISU_GaussPtsAct.h"
30 #include "VISU_GaussPointsPL.hxx"
31 #include "VISU_GaussPtsSettings.h"
32 #include "VISU_GaussPtsDeviceActor.h"
33 #include "VISU_WidgetCtrl.hxx"
34 #include "VISU_SphereWidget.hxx"
35 #include "VISU_OpenGLPointSpriteMapper.hxx"
36 #include "VISU_ScalarBarCtrl.hxx"
37 #include "VISU_ScalarBarActor.hxx"
38
39 #include "SALOME_ExtractGeometry.h"
40
41 #include "VISU_Event.h" 
42 #include "SVTK_Actor.h"
43
44 #include <vtkCamera.h>
45 #include <vtkRenderer.h>
46 #include <vtkPointPicker.h>
47 #include <vtkScalarBarWidget.h>
48 #include <vtkScalarBarActor.h>
49 #include <vtkTextMapper.h>
50 #include <vtkTextProperty.h>
51
52 #include <vtkCellData.h>
53 #include <vtkPointData.h>
54
55 #include <vtkDataArray.h>
56 #include <vtkFloatArray.h>
57
58 #include <vtkSphereSource.h>
59 #include <vtkPolyDataMapper.h>
60 #include <vtkPolyData.h>
61 #include <vtkActor.h>
62
63 #include <vtkObjectFactory.h>
64 #include <vtkCallbackCommand.h>
65 #include <vtkInteractorStyle.h>
66 #include <vtkRenderWindowInteractor.h>
67 #include <vtkOutlineSource.h>
68
69 #include <sstream>
70 #include <boost/bind.hpp>
71
72 #include <vtkUnstructuredGrid.h>
73 #include <vtkDataSetMapper.h>
74 #include <vtkRenderWindow.h>
75 #include <vtkCellArray.h>
76 #include <vtkCell.h>
77 #include <vtkMath.h>
78
79 #include <vtkViewport.h>
80
81 #include "utilities.h"
82
83 #ifdef _DEBUG_
84 static int MYDEBUG = 0;
85 static int MYDEBUG1 = 0;
86 static int MYDEBUG2 = 0;
87 #else
88 static int MYDEBUG = 0;
89 static int MYDEBUG1 = 0;
90 static int MYDEBUG2 = 0;
91 #endif
92
93
94 //============================================================================
95 vtkStandardNewMacro(VISU_GaussPtsAct);
96
97 //----------------------------------------------------------------------------
98 VISU_GaussPtsAct
99 ::VISU_GaussPtsAct():
100   myEventCallbackCommand(vtkCallbackCommand::New()),
101   myPriority(0.0),
102   myDeviceActor(VISU_GaussPtsDeviceActor::New()),
103   myWidgetCtrl(NULL),
104   myGaussPointsPL(NULL),
105   myLastObjPointID(-1),
106   myTextActor(VISU_FramedTextActor::New()),
107   myCursorPyramid(VISU_CursorPyramid::New()),
108   myCursorPyramidSelected(VISU_CursorPyramid::New()),
109   myCellSource(vtkUnstructuredGrid::New()),
110   myCellActor(SVTK_Actor::New()),
111   myScalarBarCtrl(VISU_ScalarBarCtrl::New()),
112   myBarVisibility(true),
113   myPickingSettings(NULL),
114   myInsideCursorSettings(NULL),
115   myCurrentPL(NULL)
116 {
117   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::VISU_GaussPtsAct - this = "<<this);
118
119   myEventCallbackCommand->Delete();
120   myDeviceActor->Delete();
121   myTextActor->Delete();
122
123   myCursorPyramid->Delete();
124   myCursorPyramid->SetPickable(0);
125   myCursorPyramid->SetVisibility(0);
126
127   myCursorPyramidSelected->Delete();
128   myCursorPyramidSelected->SetPickable(0);
129   myCursorPyramidSelected->SetVisibility(0);
130
131   myCellSource->Delete();
132   myCellActor->Delete();
133
134   myEventCallbackCommand->SetClientData(this); 
135   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct::ProcessEvents);
136
137   myDeviceActor->SetProperty(GetProperty());
138   myDeviceActor->SetVisibility(true);
139   myDeviceActor->SetPickable(false);
140
141   myTextActor->SetVisibility(false);
142   myTextActor->SetPickable(false);
143
144   myCellSource->Allocate();
145   myCellActor->Initialize();
146   myCellActor->SetRepresentation(VTK_WIREFRAME);
147   myCellActor->SetSource(myCellSource.GetPointer());
148   
149   myCellActor->SetVisibility(0);
150   myCellActor->SetPickable(0);
151   myCellActor->GetProperty()->SetAmbient(1.0);
152   myCellActor->GetProperty()->SetDiffuse(0.0);
153
154   myScalarBarCtrl->Delete();
155 }
156
157 VISU_GaussPtsAct
158 ::~VISU_GaussPtsAct()
159 {
160   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::~VISU_GaussPtsAct - this = "<<this);
161   SetWidgetCtrl(NULL);
162   SetInteractor(NULL);
163   SetPickingSettings(NULL);
164   SetInsideCursorSettings(NULL);
165 }
166
167
168 //----------------------------------------------------------------------------
169 void
170 VISU_GaussPtsAct
171 ::SetPipeLine(VISU_PipeLine* thePipeLine) 
172 {
173   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetPipeLine - this = "<<this);
174
175   myGaussPointsPL = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine);
176
177   Superclass::SetPipeLine(thePipeLine);
178 }
179
180 VISU_GaussPointsPL*
181 VISU_GaussPtsAct
182 ::GetGaussPointsPL()
183 {
184   return myGaussPointsPL.GetPointer();
185 }
186
187 void
188 VISU_GaussPtsAct
189 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
190 {
191   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::ShallowCopyPL - this = "<<this);
192
193   Superclass::ShallowCopyPL(thePipeLine);
194
195   UpdateInsideCursorSettings();
196
197   Highlight(isHighlighted());
198 }
199
200
201 //----------------------------------------------------------------------------
202 vtkMapper* 
203 VISU_GaussPtsAct
204 ::GetMapper()
205 {
206   myMapper->Update();
207   return Superclass::GetMapper();
208 }
209
210 float* 
211 VISU_GaussPtsAct
212 ::GetBounds()
213 {
214   return GetMapper()->GetBounds();
215 }
216
217 vtkDataSet* 
218 VISU_GaussPtsAct
219 ::GetInput()
220 {
221   return GetMapper()->GetInput();
222 }
223
224 VISU_PipeLine* 
225 VISU_GaussPtsAct
226 ::GetCurrentPL() 
227
228   return myCurrentPL;
229 }
230
231
232 //----------------------------------------------------------------------------
233 void
234 VISU_GaussPtsAct
235 ::AddToRender(vtkRenderer* theRenderer)
236 {
237   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::AddToRender - this = "<<this);
238
239   Superclass::AddToRender(theRenderer);
240
241   myDeviceActor->AddToRender(theRenderer);
242
243   theRenderer->AddActor(myTextActor.GetPointer());
244   theRenderer->AddActor(myCellActor.GetPointer());
245
246   myCursorPyramid->AddToRender(theRenderer);
247   myCursorPyramidSelected->AddToRender(theRenderer);
248   myScalarBarCtrl->AddToRender(theRenderer);
249 }
250
251 void 
252 VISU_GaussPtsAct
253 ::RemoveFromRender(vtkRenderer* theRenderer)
254 {
255   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::RemoveFromRender - this = "<<this);
256
257   Superclass::RemoveFromRender(theRenderer);
258
259   myDeviceActor->RemoveFromRender(theRenderer);
260   
261   theRenderer->RemoveActor(myTextActor.GetPointer());
262   theRenderer->RemoveActor(myCellActor.GetPointer());
263   
264   myCursorPyramid->RemoveFromRender(theRenderer);
265   myCursorPyramidSelected->RemoveFromRender(theRenderer);
266   myScalarBarCtrl->RemoveFromRender(theRenderer);
267 }
268
269 void 
270 VISU_GaussPtsAct
271 ::SetTransform(VTKViewer_Transform* theTransform)
272 {
273   Superclass::SetTransform(theTransform);
274
275   myDeviceActor->SetTransform(theTransform);
276 }
277
278 int
279 VISU_GaussPtsAct
280 ::RenderOpaqueGeometry(vtkViewport *viewport)
281 {
282   return 1;
283 }
284
285 int
286 VISU_GaussPtsAct
287 ::RenderTranslucentGeometry(vtkViewport *viewport)
288 {
289   return 1;
290 }
291
292
293 //----------------------------------------------------------------------------
294 void
295 VISU_GaussPtsAct
296 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
297 {
298   if(myWidgetCtrl == theWidgetCtrl)
299     return;
300
301   if(MYDEBUG) 
302     MESSAGE("VISU_GaussPtsAct::SetWidgetCtrl - this = "<<this<<"; theWidget = "<<theWidgetCtrl);
303
304   if(myWidgetCtrl)
305     myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
306
307   if(theWidgetCtrl){
308     theWidgetCtrl->AddObserver(vtkCommand::EnableEvent, 
309                                myEventCallbackCommand.GetPointer(), 
310                                myPriority);
311     theWidgetCtrl->AddObserver(vtkCommand::DisableEvent, 
312                                myEventCallbackCommand.GetPointer(), 
313                                myPriority);
314     theWidgetCtrl->AddObserver(vtkCommand::StartInteractionEvent, 
315                                myEventCallbackCommand.GetPointer(), 
316                                myPriority);
317     theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent, 
318                                myEventCallbackCommand.GetPointer(), 
319                                myPriority);
320   }
321
322   myWidgetCtrl = theWidgetCtrl;
323 }
324
325 bool
326 VISU_GaussPtsAct
327 ::GetChangeMagnification()
328 {
329   return myChangeMagnification;
330 }
331
332 void
333 VISU_GaussPtsAct
334 ::ChangeMagnification( bool up )
335 {
336   myEventCallbackCommand->SetAbortFlag(1);
337
338   float aMagnification = myInsideCursorSettings->GetMagnification();
339   float anIncrement = myInsideCursorSettings->GetIncrement();
340   float coefficient = up ? anIncrement : 1 / anIncrement;
341
342   myInsideCursorSettings->SetMagnification( aMagnification * coefficient );
343   myInsideCursorSettings->InvokeEvent(VISU::UpdateFromSettingsEvent,NULL);
344
345   Update();
346 }
347
348 //----------------------------------------------------------------------------
349 namespace
350 {
351   VISU_GaussPointsPL*
352   CreatePipeLine(VISU_GaussPointsPL* thePipeLine)
353   {
354     VISU_GaussPointsPL* aPipeLine = VISU_GaussPointsPL::New();
355     aPipeLine->SetGaussPtsIDMapper(thePipeLine->GetGaussPtsIDMapper());
356     aPipeLine->ShallowCopy(thePipeLine);
357     aPipeLine->Update();
358     return aPipeLine;
359   }
360 }
361
362 void
363 VISU_GaussPtsAct
364 ::SetMapperInput(vtkDataSet* theDataSet) 
365 {
366   if(MYDEBUG) MESSAGE("VISU_GaussPtsAct::SetMapperInput - this = "<<this);
367
368   myDeviceActor->SetPipeLine(GetGaussPointsPL());
369   myCurrentPL = myDeviceActor->GetPipeLine();
370
371   myMapper->SetInput(myCurrentPL->GetPickableDataSet());
372   SetMapper(myMapper.GetPointer());
373 }
374
375
376 //----------------------------------------------------------------------------
377 namespace
378 {
379   inline  
380   float 
381   GetRadius(vtkIdType theVTKID,
382             vtkDataArray *theScalarArray,
383             VISU_GaussPointsPL* theGaussPointsPL)
384   {
385     float aRadius = 0.5;
386     if(theGaussPointsPL->GetPSMapper()->GetPointSpriteMode() == 1) // Geometry mode
387       aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize();
388     else if(theGaussPointsPL->GetBicolor()){
389       float aVal = theScalarArray->GetTuple1(theVTKID);
390       if(aVal > 0.0)
391         aRadius *= theGaussPointsPL->GetMaxSize();
392       else
393         aRadius *= theGaussPointsPL->GetMinSize();
394       aRadius *= theGaussPointsPL->GetAverageCellSize();
395     }else
396       aRadius *= theGaussPointsPL->GetPointSize(theVTKID,theScalarArray);
397
398     return aRadius;
399   }
400 }
401
402 float
403 VISU_GaussPtsAct
404 ::GetRadius(vtkIdType theObjID,
405             vtkIdType theVTKID,
406             vtkDataArray *theScalarArray)
407 {
408   return ::GetRadius(theVTKID,theScalarArray,myDeviceActor->GetPipeLine());
409 }
410
411 //----------------------------------------------------------------------------
412 float 
413 VISU_GaussPtsAct
414 ::GetMagnification(vtkIdType theObjID)
415 {
416   return myDeviceActor->GetPipeLine()->GetMagnification();
417 }
418
419
420 //----------------------------------------------------------------------------
421 namespace
422 {
423   inline  
424   float 
425   GetClamp(VISU_GaussPointsPL* theGaussPointsPL)
426   {
427     float aClamp = theGaussPointsPL->GetClamp();
428     if(theGaussPointsPL->GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere)
429       return -aClamp;
430     return aClamp;
431   }
432 }
433
434 float 
435 VISU_GaussPtsAct
436 ::GetClamp(vtkIdType theObjID)
437 {
438   return ::GetClamp(myDeviceActor->GetPipeLine());
439 }
440
441
442 //----------------------------------------------------------------------------
443 void
444 VISU_GaussPtsAct
445 ::SetFactory(VISU::TActorFactory* theActorFactory)
446
447   using namespace VISU;
448   myGaussPtsActorFactory = dynamic_cast<TGaussPtsActorFactory*>(theActorFactory);
449   myUpdatePrs3dSignal.connect(boost::bind(&TGaussPtsActorFactory::UpdateFromActor,
450                                           myGaussPtsActorFactory,
451                                           _1));
452   Superclass::SetFactory(theActorFactory);
453 }
454
455 VISU::TGaussPtsActorFactory*
456 VISU_GaussPtsAct
457 ::GetGaussPtsFactory()
458 {
459   return myGaussPtsActorFactory;
460 }
461
462
463 //----------------------------------------------------------------------------
464 void
465 VISU_GaussPtsAct
466 ::SetVisibility(int theMode)
467 {
468   Superclass::SetVisibility(theMode);
469   myScalarBarCtrl->SetVisibility(theMode);
470   Highlight(isHighlighted());
471 }
472
473 int
474 VISU_GaussPtsAct
475 ::IsSegmentationEnabled()
476 {
477   return myWidgetCtrl  && myWidgetCtrl->GetEnabled();
478 }
479
480
481 //----------------------------------------------------------------------------
482 void
483 VISU_GaussPtsAct
484 ::SetBarVisibility(bool theMode)
485 {
486   myBarVisibility = theMode;
487   myScalarBarCtrl->SetCtrlVisibility(theMode); 
488   myScalarBarCtrl->SetVisibility(GetVisibility()); 
489 }
490
491 bool
492 VISU_GaussPtsAct
493 ::GetBarVisibility()
494
495   return myBarVisibility;
496 }
497
498 VISU_ScalarBarCtrl* 
499 VISU_GaussPtsAct
500 ::GetScalarBarCtrl()
501 {
502   return myScalarBarCtrl.GetPointer();
503 }
504
505 //----------------------------------------------------------------------------
506 void
507 VISU_GaussPtsAct
508 ::SetInteractor(vtkRenderWindowInteractor* theInteractor)
509 {
510   if(theInteractor == myInteractor)
511     return;
512
513   if(myInteractor)
514     myInteractor->RemoveObserver(myEventCallbackCommand.GetPointer());
515   
516   if(theInteractor){
517     theInteractor->AddObserver(vtkCommand::CharEvent, 
518                                myEventCallbackCommand.GetPointer(), 
519                                myPriority);
520     theInteractor->AddObserver(VISU::SetSMDecreaseMagnificationEvent, 
521                                myEventCallbackCommand.GetPointer(), 
522                                myPriority);
523     theInteractor->AddObserver(VISU::SetSMIncreaseMagnificationEvent, 
524                                myEventCallbackCommand.GetPointer(), 
525                                myPriority);
526   }
527   Superclass::SetInteractor(theInteractor);
528
529   Modified();
530 }
531 //-------------------------------------------------------------------------
532 void 
533 VISU_GaussPtsAct
534 ::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
535                 unsigned long theEvent,
536                 void* theClientData, 
537                 void* vtkNotUsed(theCallData))
538 {
539   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
540     if(VISU_GaussPtsAct* self = dynamic_cast<VISU_GaussPtsAct*>(anObject)) {
541       if(theEvent == VISU::UpdateInsideSettingsEvent)
542         self->UpdateInsideCursorSettings();
543       else
544         self->OnInteractorEvent(theEvent);
545     }
546 }
547
548 //-------------------------------------------------------------------------
549 void
550 VISU_GaussPtsAct
551 ::OnInteractorEvent(unsigned long theEvent)
552 {
553   switch(theEvent){
554   case vtkCommand::CharEvent: {
555     switch(myInteractor->GetKeyCode()) {
556     case 'M' :
557     case 'm' :
558     {
559       if( myWidgetCtrl->GetEnabled() )
560       {
561         this->ChangeMagnification( myInteractor->GetShiftKey() );
562         return;
563       }
564
565       myChangeMagnification = myInteractor->GetShiftKey();
566       break;
567     }
568     case 'D' :
569     case 'd' :
570     {
571       if( myWidgetCtrl->GetEnabled() && myWidgetCtrl->IsSphereActive() )
572       {
573         VISU_SphereWidget* aSphereWidget = myWidgetCtrl->GetSphereWidget();
574         aSphereWidget->ChangeRadius( myInteractor->GetShiftKey() );
575         myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
576         myWidgetCtrl->GetInteractor()->Render();
577       }
578       return;
579     }
580     default:
581       return;
582     }
583     myUpdatePrs3dSignal(this);
584     break;
585   }
586   case VISU::SetSMDecreaseMagnificationEvent: 
587   case VISU::SetSMIncreaseMagnificationEvent: 
588     myChangeMagnification = theEvent == VISU::SetSMIncreaseMagnificationEvent;
589     myUpdatePrs3dSignal(this);
590     break;
591   case VISU::UpdatePickingSettingsEvent:
592     UpdatePickingSettings();
593     break;
594   case vtkCommand::EndInteractionEvent:
595   case vtkCommand::EnableEvent:
596   case vtkCommand::DisableEvent: 
597     myCurrentPL->GetMapper()->Update();
598     Highlight(isHighlighted());
599     break;
600   default:
601     break;
602   }
603 }
604
605 //----------------------------------------------------------------------------
606 bool VISU_GaussPtsAct::IsInfinitive()
607 {
608   if(vtkMapper* aMapper = myDeviceActor->GetMapper()){
609     if(vtkDataSet* aDataSet= aMapper->GetInput()){
610       aDataSet->Update();
611       myIsInfinite = aDataSet->GetNumberOfCells() < 2;
612     }
613   }
614   return myIsInfinite;
615 }
616
617 //----------------------------------------------------------------------------
618 bool
619 VISU_GaussPtsAct
620 ::PreHighlight(vtkInteractorStyle* theInteractorStyle, 
621                SVTK_SelectionEvent* theSelectionEvent,
622                bool theIsHighlight)
623 {
624   myPreHighlightActor->SetVisibility(false);
625   myCursorPyramid->SetVisibility(false);  
626
627   if (!myBarVisibility) {
628     return false;
629   }
630
631   if(!theIsHighlight)
632     myLastObjPointID = -1;
633
634   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
635
636   if(aSelectionMode == ActorSelection || !theIsHighlight)
637     return Superclass::PreHighlight(theInteractorStyle,
638                                     theSelectionEvent,
639                                     theIsHighlight);  
640   
641   bool anIsChanged = (mySelectionMode != aSelectionMode);
642   bool anIsPreselected = myIsPreselected;
643   myIsPreselected = false;
644   
645   if(aSelectionMode == GaussPointSelection && theIsHighlight){
646     myPointPicker->Pick(theSelectionEvent->myX, 
647                         theSelectionEvent->myY, 
648                         0.0, 
649                         theInteractorStyle->GetCurrentRenderer());
650     
651     if(myPointPicker->GetActor() != this)
652       return (anIsPreselected != myIsPreselected);
653     
654     vtkIdType aVtkId = myPointPicker->GetPointId();
655     
656     if(aVtkId >= 0 && mySelector->IsValid(this,aVtkId,true) && hasIO()){
657       vtkIdType anObjId = GetNodeObjId( aVtkId );
658       myIsPreselected = (anObjId >= 0);
659       if(myIsPreselected){
660         anIsChanged = (myLastObjPointID != anObjId);
661         if(anIsChanged){
662           float* aNodeCoord = GetNodeCoord(anObjId);
663           vtkDataSet* aDataSet = GetInput();
664           vtkCellData* aCellData = aDataSet->GetCellData();
665           if(vtkDataArray *aScalarArray = aCellData->GetScalars()){
666             float aPyramidHeight = myPickingSettings->GetPyramidHeight();
667             aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
668             //float aColor[3] = myPreHighlightActor->GetProperty()->GetColor();
669             float aColor[3];
670             theInteractorStyle->GetCurrentRenderer()->GetBackground( aColor );
671             aColor[0] = 1. - aColor[0];
672             aColor[1] = 1. - aColor[1];
673             aColor[2] = 1. - aColor[2];
674
675             myCursorPyramid->Init(aPyramidHeight,
676                                   myPickingSettings->GetCursorSize(),
677                                   GetRadius(anObjId,aVtkId,aScalarArray),
678                                   GetMagnification(anObjId),
679                                   GetClamp(anObjId),
680                                   aNodeCoord,
681                                   aColor);
682           }
683           myLastObjPointID = anObjId;
684         }
685         myCursorPyramid->SetVisibility(true);
686       }
687     }
688   }
689   
690   mySelectionMode = aSelectionMode;
691   anIsChanged |= (anIsPreselected != myIsPreselected);
692
693   return anIsChanged;
694 }
695
696
697 //----------------------------------------------------------------------------
698 inline
699 void
700 ChangeZoom(VISU_PickingSettings *thePickingSettings,
701            vtkInteractorStyle* theInteractorStyle,
702            int theInitialHasIndex,
703            SVTK_Selector* theSelector,
704            const Handle(SALOME_InteractiveObject)& theIO)
705 {
706   int aCurrentHasIndex = theSelector->HasIndex(theIO);
707
708   if(theInitialHasIndex + aCurrentHasIndex == 1){
709     vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
710     vtkCamera *aCamera = aRenderer->GetActiveCamera();
711     float aZoomFactor = thePickingSettings->GetZoomFactor();
712     double aScale = aCamera->GetParallelScale();
713     if (!theInitialHasIndex && aCurrentHasIndex) {
714       aCamera->SetParallelScale(aScale/aZoomFactor);
715     }
716     else {
717       aCamera->SetParallelScale(aScale*aZoomFactor);
718     }
719   }
720   
721 }
722
723 bool
724 VISU_GaussPtsAct
725 ::Highlight(vtkInteractorStyle* theInteractorStyle, 
726             SVTK_SelectionEvent* theSelectionEvent,
727             bool theIsHighlight)
728
729   myIsHighlighted = false;
730   Handle(SALOME_InteractiveObject) anIO = getIO();
731   int anInitialHasIndex = mySelector->HasIndex(anIO);
732
733   Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode;
734   //
735   if(!theIsHighlight && aSelectionMode == GaussPointSelection){
736     mySelector->RemoveIObject(anIO);
737
738     ChangeZoom(myPickingSettings,
739                theInteractorStyle,
740                anInitialHasIndex,
741                mySelector.GetPointer(),
742                anIO);
743
744     return true;
745   }
746   
747   if (!myBarVisibility) {
748     return false;
749   }
750   //
751   if(aSelectionMode == ActorSelection){
752     return Superclass::Highlight(theInteractorStyle,
753                                  theSelectionEvent,
754                                  theIsHighlight);
755   }
756   //
757   if(aSelectionMode == GaussPointSelection && !theSelectionEvent->myIsRectangle){
758
759     vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer();
760     myPointPicker->Pick(theSelectionEvent->myX, 
761                         theSelectionEvent->myY,
762                         0.0, 
763                         aRenderer);
764
765     if(myPointPicker->GetActor() != this) {
766       mySelector->ClearIObjects();
767
768       ChangeZoom(myPickingSettings,
769                  theInteractorStyle,
770                  anInitialHasIndex,
771                  mySelector.GetPointer(),
772                  anIO);
773
774       return true;
775     }
776
777     vtkIdType aVtkId = myPointPicker->GetPointId();
778     if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) {
779       vtkIdType anObjId = GetNodeObjId( aVtkId );
780       if(anObjId >= 0){
781         myIsHighlighted = true;
782         // Update the Selector
783         if(mySelector->IsSelected(myIO))
784           mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
785         else{
786           if(!theSelectionEvent->myIsShift){
787             mySelector->ClearIObjects();
788           }
789           mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift);
790           mySelector->AddIObject(this);
791         }
792         //
793         float* aNodeCoord = GetNodeCoord(anObjId);
794         //
795         // FlyTo
796         vtkRenderWindowInteractor* anInteractor = theInteractorStyle->GetInteractor();
797         float aDollyWas = anInteractor->GetDolly();
798         int aNumberOfFlyFramesWas = anInteractor->GetNumberOfFlyFrames();
799         
800         anInteractor->SetDolly(0.);
801         anInteractor->SetNumberOfFlyFrames(myPickingSettings->GetStepNumber());
802         anInteractor->FlyTo(aRenderer,aNodeCoord);
803         aRenderer->ResetCameraClippingRange();
804         anInteractor->SetDolly(aDollyWas);
805         anInteractor->SetNumberOfFlyFrames(aNumberOfFlyFramesWas);
806         
807         mySelectionMode = aSelectionMode;
808
809         ChangeZoom(myPickingSettings,
810                    theInteractorStyle,
811                    anInitialHasIndex,
812                    mySelector.GetPointer(),
813                    anIO);
814
815         return true;
816         //
817       }// if( anObjId >= 0 ) {
818     }//if( aVtkId >= 0  && mySelector->IsValid( this, aVtkId, true ) && hasIO()) 
819   }//if(!theSelectionEvent->myIsRectangle){
820
821   ChangeZoom(myPickingSettings,
822              theInteractorStyle,
823              anInitialHasIndex,
824              mySelector.GetPointer(),
825              anIO);
826   
827   return false;
828 }
829
830 //==================================================================
831 // function : Highlight
832 // purpose  :
833 //==================================================================
834 void
835 VISU_GaussPtsAct
836 ::Highlight(bool theIsHighlight)
837 {
838   if(!mySelector.GetPointer())
839     return;
840
841   myOutlineActor->SetVisibility(false);
842   myTextActor->SetVisibility(0);
843   myCursorPyramidSelected->SetVisibility(0);
844   myCursorPyramid->SetVisibility(0);
845   myCellActor->SetVisibility(0);
846   GetScalarBarCtrl()->SetIsMarked(false);
847   GetScalarBarCtrl()->Update();
848
849   bool anIsVisible = GetVisibility();
850
851   Selection_Mode aSelectionMode = mySelector->SelectionMode();
852
853   if(aSelectionMode == ActorSelection)
854     Superclass::highlight(theIsHighlight);
855   else if(aSelectionMode != GaussPointSelection)
856     return;
857
858   TColStd_IndexedMapOfInteger aMapIndex;
859   mySelector->GetIndex( getIO(), aMapIndex );
860   if(aMapIndex.Extent() != 1 || !myBarVisibility) {
861     return;
862   }
863   //
864   std::ostringstream aStr;
865   int anObjId = aMapIndex(1);
866   aStr<<"Global ID: "<<anObjId;
867   //
868   vtkIdType aVtkId = GetNodeVTKID(anObjId);
869   if(aVtkId >= 0){
870     float *aNodeCoord = GetNodeCoord(anObjId);
871     float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.};
872     //
873     vtkDataSet* aDataSet = GetInput();
874     vtkCellData* aDataSetAttributes = aDataSet->GetCellData();
875     //
876     if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){
877       float aVal = aScalarArray->GetTuple1(aVtkId);
878       //
879       GetScalarBarCtrl()->SetIsMarked(true);
880       GetScalarBarCtrl()->SetMarkValue(aVal);
881       GetScalarBarCtrl()->Update();
882       //
883       float aPyramidHeight = myPickingSettings->GetPyramidHeight();
884       aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize();
885       myCursorPyramidSelected->Init(aPyramidHeight,
886                                     myPickingSettings->GetCursorSize(),
887                                     GetRadius(anObjId,aVtkId,aScalarArray),
888                                     GetMagnification(anObjId),
889                                     GetClamp(anObjId),
890                                     aNodeCoord,
891                                     myHighlightActor->GetProperty()->GetColor());
892       myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight);
893       //
894       const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
895         myGaussPointsPL->GetGaussPtsIDMapper();
896       VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
897       
898       VISU::TGaussPointID aGaussPointID = myGaussPointsPL->GetObjID(anObjId);
899       VISU::TCellID aCellID = aGaussPointID.first;
900       VISU::TLocalPntID aLocalPntID = aGaussPointID.second;
901       aStr<<"\nParentCellID: "<<aCellID;
902       std::string aParentName = aParent->GetElemName(aCellID);
903       if(aParentName != "") {
904         aStr<<"\nParentCellName: '"<<aParentName<<"'";
905       }
906       aStr<<"\nLocalPntID: "<<aLocalPntID;
907       aStr<<"\nScalar: "<<aVal;
908     }
909
910     if(vtkDataArray* aFieldArray = aDataSetAttributes->GetArray("VISU_FIELD")){
911       if(vtkFloatArray *aFloatArray = dynamic_cast<vtkFloatArray*>(aFieldArray)){
912         int aNbComp = aFloatArray->GetNumberOfComponents();
913         aStr<<"\nData: {";
914         int anId = 0;
915         while(anId < aNbComp){
916           float aComp = aFloatArray->GetComponent(aVtkId,anId++);
917           aStr<<aComp;
918           if(anId < aNbComp)
919             aStr<<"; ";
920         }
921         aStr<<"}";
922       }
923     }
924     //
925     // myTextActor
926     std::string aString = aStr.str();
927     myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
928     myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
929     myTextActor->SetWorldPoint(aWorldCoord);
930     myTextActor->SetText(aString.c_str());
931     myTextActor->SetVisibility(anIsVisible && theIsHighlight);
932     //
933     // myCellActor
934     if(myPickingSettings->GetDisplayParentMesh()){
935       const VISU::PGaussPtsIDMapper& aGaussPtsIDMapper = 
936         myGaussPointsPL->GetGaussPtsIDMapper();
937       VISU::TNamedIDMapper* aParent = aGaussPtsIDMapper->GetParent();
938       
939       myCellSource->Reset();
940       myCellSource->Modified(); // a VTK bug
941       myCellSource->SetPoints(aParent->GetVTKOutput()->GetPoints());
942       
943       VISU::TGaussPointID aGaussPointID = aGaussPtsIDMapper->GetObjID(anObjId);
944       vtkIdType aCellID = aGaussPointID.first;
945       vtkCell* aCell = aParent->GetElemCell(aCellID);
946       myCellSource->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds());
947       myCellActor->SetVisibility(anIsVisible && theIsHighlight);
948       myCellActor->SetRepresentation(VTK_WIREFRAME);
949     }
950   }
951 }
952
953
954 //----------------------------------------------------------------
955 void
956 VISU_GaussPtsAct
957 ::SetPickingSettings(VISU_PickingSettings* thePickingSettings)
958 {
959   if(myPickingSettings == thePickingSettings)
960     return;
961
962   if(myPickingSettings)
963     myPickingSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
964
965   myPickingSettings = thePickingSettings;
966
967   if(thePickingSettings)
968   {
969     thePickingSettings->AddObserver(VISU::UpdatePickingSettingsEvent, 
970                                     myEventCallbackCommand.GetPointer(), 
971                                     myPriority);
972     this->UpdatePickingSettings();
973   }
974 }
975
976 void
977 VISU_GaussPtsAct
978 ::UpdatePickingSettings()
979 {
980   if(!myPickingSettings || myPickingSettings->GetInitial())
981     return;
982
983   myTextActor->SetModePosition(myPickingSettings->GetInfoWindowPosition());
984   myTextActor->SetTransparency(myPickingSettings->GetInfoWindowTransparency());
985
986   float aHeight = myGaussPointsPL->GetMaxPointSize()*myPickingSettings->GetPyramidHeight();
987   float aCursorSize = myPickingSettings->GetCursorSize();
988   myCursorPyramid->SetPreferences(aHeight,aCursorSize);
989   myCursorPyramidSelected->SetPreferences(aHeight,aCursorSize);
990
991   myHighlightActor->GetProperty()->SetColor( myPickingSettings->GetColor() );
992   myPointPicker->SetTolerance( myPickingSettings->GetPointTolerance() );
993
994   Highlight(isHighlighted());
995
996   Update();
997 }
998
999 //----------------------------------------------------------------
1000 void
1001 VISU_GaussPtsAct
1002 ::SetInsideCursorSettings(VISU_InsideCursorSettings* theInsideCursorSettings)
1003 {
1004   if(myInsideCursorSettings == theInsideCursorSettings)
1005     return;
1006
1007   if(myInsideCursorSettings)
1008     myInsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1009
1010   myInsideCursorSettings = theInsideCursorSettings;
1011
1012   if(theInsideCursorSettings){
1013     theInsideCursorSettings->AddObserver(VISU::UpdateInsideSettingsEvent, 
1014                                          myEventCallbackCommand.GetPointer(), 
1015                                          myPriority);
1016     UpdateInsideCursorSettings();
1017   }
1018 }
1019
1020 void
1021 VISU_GaussPtsAct
1022 ::UpdateInsideCursorSettings()
1023 {
1024   UpdateInsideCursorSettings( myDeviceActor );
1025 }
1026
1027 void
1028 VISU_GaussPtsAct
1029 ::UpdateInsideCursorSettings( PDeviceActor theActor )
1030 {
1031   if(!myInsideCursorSettings || myInsideCursorSettings->GetInitial())
1032     return;
1033
1034   VISU_GaussPointsPL* aPipeline = theActor->GetPipeLine();
1035
1036   SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1037   vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1038
1039   aPipeline->ShallowCopy(GetGaussPointsPL());
1040
1041   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1042
1043   aPipeline->SetPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
1044   aPipeline->SetClamp( myInsideCursorSettings->GetClamp() );
1045   aPipeline->SetImageData( myInsideCursorSettings->GetTexture() );
1046   aPipeline->SetAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
1047   aPipeline->SetResolution( myInsideCursorSettings->GetResolution() );
1048   aPipeline->SetMinSize( myInsideCursorSettings->GetMinSize() );
1049   aPipeline->SetMaxSize( myInsideCursorSettings->GetMaxSize() );
1050   aPipeline->SetMagnification( myInsideCursorSettings->GetMagnification() );
1051   aPipeline->SetMagnificationIncrement( myInsideCursorSettings->GetIncrement() );
1052
1053   if( myInsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1054     theActor->GetProperty()->SetRepresentation( VTK_POINTS );
1055   else
1056     theActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1057
1058   aPipeline->Update();
1059
1060   Highlight(isHighlighted());
1061
1062   Update();
1063 }
1064
1065 //==============================================================================
1066 vtkStandardNewMacro(VISU_GaussPtsAct1);
1067
1068
1069 //----------------------------------------------------------------------------
1070 VISU_GaussPtsAct1
1071 ::VISU_GaussPtsAct1():
1072   myInsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1073   myOutsideDeviceActor(VISU_GaussPtsDeviceActor::New()),
1074   myOutsideCursorSettings(NULL)
1075 {
1076   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::VISU_GaussPtsAct1 - this = "<<this);
1077
1078   myEventCallbackCommand->SetCallback(VISU_GaussPtsAct1::ProcessEvents);
1079
1080   myInsideDeviceActor->SetVisibility(false);
1081   myInsideDeviceActor->SetPickable(false);
1082   myInsideDeviceActor->Delete();
1083
1084   myOutsideDeviceActor->SetVisibility(false);
1085   myOutsideDeviceActor->SetPickable(false);
1086   myOutsideDeviceActor->Delete();
1087 }
1088
1089 VISU_GaussPtsAct1
1090 ::~VISU_GaussPtsAct1()
1091 {
1092   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::~VISU_GaussPtsAct1 - this = "<<this);
1093
1094   SetOutsideCursorSettings(NULL);
1095 }
1096
1097
1098 //----------------------------------------------------------------------------
1099 void
1100 VISU_GaussPtsAct1
1101 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1102 {
1103   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::ShallowCopyPL - this = "<<this);
1104
1105   Superclass::ShallowCopyPL(thePipeLine);
1106
1107   UpdateOutsideCursorSettings();
1108 }
1109
1110
1111 //----------------------------------------------------------------------------
1112 void
1113 VISU_GaussPtsAct1
1114 ::AddToRender(vtkRenderer* theRenderer)
1115 {
1116   Superclass::AddToRender(theRenderer);
1117
1118   myInsideDeviceActor->AddToRender(theRenderer);
1119   myOutsideDeviceActor->AddToRender(theRenderer);
1120 }
1121
1122 void 
1123 VISU_GaussPtsAct1
1124 ::RemoveFromRender(vtkRenderer* theRenderer)
1125 {
1126   Superclass::RemoveFromRender(theRenderer);
1127
1128   myInsideDeviceActor->RemoveFromRender(theRenderer);
1129   myOutsideDeviceActor->RemoveFromRender(theRenderer);
1130 }
1131
1132 void 
1133 VISU_GaussPtsAct1
1134 ::SetTransform(VTKViewer_Transform* theTransform)
1135 {
1136   Superclass::SetTransform(theTransform);
1137
1138   myInsideDeviceActor->SetTransform(theTransform);
1139   myOutsideDeviceActor->SetTransform(theTransform);
1140 }
1141
1142
1143 //----------------------------------------------------------------------------
1144 void
1145 VISU_GaussPtsAct1
1146 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1147 {
1148   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetWidgetCtrl - this = "<<this);
1149
1150   if(myWidgetCtrl == theWidgetCtrl){
1151     return;
1152   }
1153
1154   if(myWidgetCtrl){
1155     myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1156     myInsideDeviceActor->SetVisibility(false);
1157
1158     myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);  
1159     myOutsideDeviceActor->SetVisibility(false);
1160   }
1161
1162   Superclass::SetWidgetCtrl(theWidgetCtrl);
1163
1164   if(theWidgetCtrl){
1165     myInsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1166     myInsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1167
1168     myOutsideDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());  
1169     myOutsideDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1170   }
1171 }
1172
1173
1174 //----------------------------------------------------------------------------
1175 void
1176 VISU_GaussPtsAct1
1177 ::SetMapperInput(vtkDataSet* theDataSet) 
1178 {
1179   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetMapperInput - this = "<<this);
1180
1181   Superclass::SetMapperInput(theDataSet);
1182
1183   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1184     myInsideDeviceActor->SetPipeLine(aPipeLine);
1185     aPipeLine->Delete();
1186   }
1187
1188   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1189     myOutsideDeviceActor->SetPipeLine(aPipeLine);
1190     aPipeLine->Delete();
1191
1192     SALOME_ExtractGeometry* anExtractGeometry = aPipeLine->GetExtractGeometryFilter();
1193     anExtractGeometry->SetExtractBoundaryCells(true);
1194     anExtractGeometry->SetExtractInside(true);
1195   }
1196 }
1197
1198
1199 //----------------------------------------------------------------------------
1200 float
1201 VISU_GaussPtsAct1
1202 ::GetRadius(vtkIdType theObjID,
1203             vtkIdType theVTKID,
1204             vtkDataArray *theScalarArray)
1205 {
1206   VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1207   if(IsSegmentationEnabled()){
1208     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1209       aPipeLine = myOutsideDeviceActor->GetPipeLine();
1210     else
1211       aPipeLine = myInsideDeviceActor->GetPipeLine();
1212   }
1213   return ::GetRadius(theVTKID,theScalarArray,aPipeLine);
1214 }
1215
1216
1217 //----------------------------------------------------------------------------
1218 float 
1219 VISU_GaussPtsAct1
1220 ::GetMagnification(vtkIdType theObjID)
1221 {
1222   VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine();
1223   if(IsSegmentationEnabled()){
1224     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1225       aPipeLine = myOutsideDeviceActor->GetPipeLine();
1226     else
1227       aPipeLine = myInsideDeviceActor->GetPipeLine();
1228   }
1229   return aPipeLine->GetMagnification();
1230 }
1231
1232
1233 //----------------------------------------------------------------------------
1234 float 
1235 VISU_GaussPtsAct1
1236 ::GetClamp(vtkIdType theObjID)
1237 {
1238   if(IsSegmentationEnabled()){
1239     if(myInsideDeviceActor->GetPipeLine()->GetNodeVTKID(theObjID) < 0)
1240       return ::GetClamp(myOutsideDeviceActor->GetPipeLine());
1241     else
1242       return ::GetClamp(myInsideDeviceActor->GetPipeLine());
1243   }
1244   return Superclass::GetClamp(theObjID);
1245 }
1246
1247
1248 //----------------------------------------------------------------
1249 void 
1250 VISU_GaussPtsAct1
1251 ::Connect(VISU_GaussPtsAct2* theActor)
1252 {
1253   mySetVisibilitySignal.connect(boost::bind(&VISU_GaussPtsAct2::SetVisibility,theActor,_1));
1254 }
1255
1256 void
1257 VISU_GaussPtsAct1
1258 ::SetVisibility(int theMode)
1259 {
1260   if(MYDEBUG1) MESSAGE("VISU_GaussPtsAct1::SetVisibility - this = "<<this);
1261
1262   Superclass::SetVisibility(theMode);
1263
1264   bool aVisisbility = GetVisibility();
1265   bool anIsSegementation = IsSegmentationEnabled();
1266   myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1267   myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1268   myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1269
1270   mySetVisibilitySignal(GetVisibility());
1271 }
1272
1273 //----------------------------------------------------------------
1274 void
1275 VISU_GaussPtsAct1
1276 ::UpdateInsideCursorSettings()
1277 {
1278   Superclass::UpdateInsideCursorSettings( myInsideDeviceActor );
1279 }
1280
1281 //----------------------------------------------------------------
1282 void
1283 VISU_GaussPtsAct1
1284 ::SetOutsideCursorSettings(VISU_OutsideCursorSettings* theOutsideCursorSettings)
1285 {
1286   if(myOutsideCursorSettings == theOutsideCursorSettings)
1287     return;
1288
1289   if(myOutsideCursorSettings)
1290     myOutsideCursorSettings->RemoveObserver(myEventCallbackCommand.GetPointer());
1291
1292   myOutsideCursorSettings = theOutsideCursorSettings;
1293
1294   if(theOutsideCursorSettings)
1295   {
1296     theOutsideCursorSettings->AddObserver(VISU::UpdateOutsideSettingsEvent, 
1297                                           myEventCallbackCommand.GetPointer(), 
1298                                           myPriority);
1299     UpdateOutsideCursorSettings();
1300   }
1301 }
1302
1303 void
1304 VISU_GaussPtsAct1
1305 ::UpdateOutsideCursorSettings()
1306 {
1307   if(!myOutsideCursorSettings || myOutsideCursorSettings->GetInitial())
1308     return;
1309
1310   VISU_GaussPointsPL* aPipeline = myOutsideDeviceActor->GetPipeLine();
1311
1312   SALOME_ExtractGeometry* anExtractGeometry = aPipeline->GetExtractGeometryFilter();
1313   vtkImplicitFunction* anImplicitFunction = anExtractGeometry->GetImplicitFunction();
1314   float aMagnification = aPipeline->GetMagnification();
1315
1316   aPipeline->ShallowCopy(GetGaussPointsPL());
1317
1318   aPipeline->SetImplicitFunction(anImplicitFunction); // To restore
1319   anExtractGeometry->SetExtractBoundaryCells(true);
1320   anExtractGeometry->SetExtractInside(true);
1321   aPipeline->SetMagnification( aMagnification );
1322
1323   aPipeline->SetPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
1324
1325   if( myOutsideCursorSettings->GetPrimitiveType() != VISU_OpenGLPointSpriteMapper::GeomSphere )
1326     myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_POINTS );
1327   else
1328     myOutsideDeviceActor->GetProperty()->SetRepresentation( VTK_SURFACE );
1329
1330   aPipeline->SetClamp( myOutsideCursorSettings->GetClamp() );
1331   aPipeline->SetImageData( myOutsideCursorSettings->GetTexture() );
1332   aPipeline->SetAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
1333   aPipeline->SetResolution( myOutsideCursorSettings->GetResolution() );
1334   aPipeline->SetSize( myOutsideCursorSettings->GetSize() );
1335   aPipeline->SetMagnification( myOutsideCursorSettings->GetMagnification() );
1336   aPipeline->SetMagnificationIncrement( myOutsideCursorSettings->GetIncrement() );
1337
1338   if( myOutsideCursorSettings->GetUniform() )
1339   {
1340     myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOff();
1341     myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 1 ); // Geometry mode
1342     myOutsideDeviceActor->GetProperty()->SetColor( myOutsideCursorSettings->GetColor() );
1343   }
1344   else
1345   {
1346     myOutsideDeviceActor->GetPSMapper()->SetPointSpriteMode( 2 ); // Outside cursor mode
1347     myOutsideDeviceActor->GetPSMapper()->SetColorModeToMapScalars();
1348     myOutsideDeviceActor->GetPSMapper()->ScalarVisibilityOn();
1349   }
1350
1351   aPipeline->Update();
1352
1353   Highlight(isHighlighted());
1354
1355   Update();
1356 }
1357
1358
1359 //----------------------------------------------------------------
1360 void 
1361 VISU_GaussPtsAct1
1362 ::ProcessEvents(vtkObject* theObject, 
1363                 unsigned long theEvent,
1364                 void* theClientData, 
1365                 void* theCallData)
1366 {
1367   if(vtkObject* anObject = reinterpret_cast<vtkObject*>(theClientData))
1368     if(VISU_GaussPtsAct1* self = dynamic_cast<VISU_GaussPtsAct1*>(anObject))
1369       if(theEvent == VISU::UpdateOutsideSettingsEvent)
1370         self->UpdateOutsideCursorSettings();
1371
1372   Superclass::ProcessEvents(theObject,theEvent,theClientData,theCallData);
1373 }
1374
1375 void
1376 VISU_GaussPtsAct1
1377 ::OnInteractorEvent(unsigned long theEvent)
1378 {
1379   switch(theEvent){
1380   case vtkCommand::StartInteractionEvent: 
1381     myDeviceActor->SetVisibility(GetVisibility());
1382     myInsideDeviceActor->SetVisibility(false);
1383     myOutsideDeviceActor->SetVisibility(false);
1384     break;
1385   case vtkCommand::EnableEvent: 
1386   case vtkCommand::DisableEvent:
1387   case vtkCommand::EndInteractionEvent: {
1388     bool aVisisbility = GetVisibility();
1389     bool anIsSegementation = IsSegmentationEnabled();
1390     myDeviceActor->SetVisibility(aVisisbility && !anIsSegementation);
1391     myInsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1392     myOutsideDeviceActor->SetVisibility(aVisisbility && anIsSegementation);
1393     break;
1394   }
1395   default:
1396     break;
1397   }
1398   
1399   Superclass::OnInteractorEvent(theEvent);
1400 }
1401
1402
1403 //==============================================================================
1404 vtkStandardNewMacro(VISU_GaussPtsAct2);
1405
1406
1407 //----------------------------------------------------------------------------
1408 VISU_GaussPtsAct2
1409 ::VISU_GaussPtsAct2()
1410 {
1411   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::VISU_GaussPtsAct2 - this = "<<this);
1412   myDeviceActor->SetVisibility(false);
1413 }
1414
1415 VISU_GaussPtsAct2
1416 ::~VISU_GaussPtsAct2()
1417 {
1418   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::~VISU_GaussPtsAct2 - this = "<<this);
1419 }
1420
1421
1422 //----------------------------------------------------------------------------
1423 void
1424 VISU_GaussPtsAct2
1425 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
1426 {
1427   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::ShallowCopyPL - this = "<<this);
1428
1429   Superclass::ShallowCopyPL(thePipeLine);
1430 }
1431
1432
1433 //----------------------------------------------------------------------------
1434 void
1435 VISU_GaussPtsAct2
1436 ::SetMapperInput(vtkDataSet* theDataSet) 
1437 {
1438   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetMapperInput - this = "<<this);
1439
1440   if(VISU_GaussPointsPL* aPipeLine = CreatePipeLine(GetGaussPointsPL())){
1441     myDeviceActor->SetPipeLine(aPipeLine);
1442     myCurrentPL = aPipeLine;
1443     aPipeLine->Delete();
1444
1445     myMapper->SetInput(myCurrentPL->GetPickableDataSet());
1446     SetMapper(myMapper.GetPointer());
1447   }
1448 }
1449
1450 //----------------------------------------------------------------------------
1451 void
1452 VISU_GaussPtsAct2
1453 ::SetWidgetCtrl(VISU_WidgetCtrl* theWidgetCtrl)
1454 {
1455   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetWidgetCtrl - this = "<<this);
1456
1457   if(myWidgetCtrl == theWidgetCtrl)
1458     return;
1459
1460   if(myWidgetCtrl){
1461     theWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
1462     myDeviceActor->GetPipeLine()->SetImplicitFunction(NULL);
1463     myDeviceActor->SetVisibility(false);
1464   }
1465
1466   Superclass::SetWidgetCtrl(theWidgetCtrl);
1467
1468   if(theWidgetCtrl){
1469     myDeviceActor->GetPipeLine()->SetImplicitFunction(theWidgetCtrl->ImplicitFunction());
1470     myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1471   }
1472 }
1473
1474
1475 //----------------------------------------------------------------------------
1476 void
1477 VISU_GaussPtsAct2
1478 ::SetVisibility(int theMode)
1479 {
1480   if(MYDEBUG2) MESSAGE("VISU_GaussPtsAct2::SetVisibility - this = "<<this);
1481
1482   Superclass::SetVisibility(theMode);
1483
1484   myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1485 }
1486
1487 void
1488 VISU_GaussPtsAct2
1489 ::OnInteractorEvent(unsigned long theEvent)
1490 {
1491   switch(theEvent){
1492   case vtkCommand::EnableEvent: 
1493   case vtkCommand::DisableEvent:
1494     myDeviceActor->SetVisibility(GetVisibility() && IsSegmentationEnabled());
1495     if(theEvent == vtkCommand::EnableEvent)
1496       Update();
1497     break;
1498   case vtkCommand::EndInteractionEvent:
1499     Update();
1500     break;
1501   default:
1502     break;
1503   }
1504   Superclass::OnInteractorEvent(theEvent);
1505 }