Salome HOME
IPAL21489 Filter by Scalars... does not show visible elements for some presentations.
[modules/visu.git] / src / VISU_I / VISU_ColoredPrs3d_i.hh
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU OBJECT : interactive object for VISU entities implementation
23 //  File   : VISU_ColoredPrs3d_i.hh
24 //  Author : Alexey PETROV
25 //  Module : VISU
26 //
27 #ifndef VISU_ColoredPrs3d_i_HeaderFile
28 #define VISU_ColoredPrs3d_i_HeaderFile
29
30 #include "VISU_Prs3d_i.hh"
31 #include "VISU_Result_i.hh"
32 #include "VISU_BoostSignals.h"
33 #include "SALOME_GenericObjPointer.hh"
34
35 #include <set>
36
37 class VISU_ColoredPL;
38
39 namespace VISU
40 {
41   class ColoredPrs3d_i;
42
43   //----------------------------------------------------------------------------
44   struct TMinMaxController
45   {
46     virtual
47     void
48     UpdateReference(ColoredPrs3d_i* theFromPrs3, ColoredPrs3d_i* theToPrs3d);
49
50     virtual
51     vtkFloatingPointType
52     GetComponentMin(vtkIdType theCompID);
53
54     virtual
55     vtkFloatingPointType
56     GetComponentMax(vtkIdType theCompID);
57
58     virtual
59     void
60     Register() = 0;
61
62     virtual
63     void
64     Destroy() = 0;
65   };
66   typedef SALOME::GenericObjPtr<TMinMaxController> PMinMaxController;
67
68
69   //----------------------------------------------------------------------------
70   struct TVTKMinMaxController: virtual TMinMaxController,
71                                virtual vtkObjectBase
72   {
73     virtual
74     void
75     Register()
76     {
77       vtkObjectBase::Register(NULL);
78     }
79
80     virtual
81     void
82     Destroy()
83     {
84       vtkObjectBase::Delete();
85     }
86   };
87
88
89   //----------------------------------------------------------------------------
90   PMinMaxController
91   CreateDefaultMinMaxController(VISU::ColoredPrs3d_i* theColoredPrs3d);
92   
93
94   //----------------------------------------------------------------------------
95   class VISU_I_EXPORT ColoredPrs3d_i : public virtual POA_VISU::ColoredPrs3d,
96                                        public virtual TMinMaxController,
97                                        public virtual TResultObserver,
98                                        public virtual Prs3d_i
99   {
100     ColoredPrs3d_i(const ColoredPrs3d_i&);
101
102   public:
103     //----------------------------------------------------------------------------
104     typedef Prs3d_i TSuperClass;
105     typedef VISU::ColoredPrs3d TInterface;
106
107     /*! 
108       The enumeration allow to define what mode should be used for the presentation building.
109     */
110     VISU_I_EXPORT enum EPublishInStudyMode {EPublishUnderTimeStamp, EPublishIndependently, ERegisterInCache, EDoNotPublish};
111
112     explicit
113     ColoredPrs3d_i(EPublishInStudyMode thePublishInStudyMode);
114
115     virtual
116     ~ColoredPrs3d_i();
117
118     virtual
119     void
120     Register();
121
122     virtual
123     void
124     Destroy();
125
126     virtual
127     void
128     RemoveFromStudy();
129
130     //----------------------------------------------------------------------------
131     //! To update the presentation from result in automatic way
132     virtual
133     void
134     UpdateFromResult(Result_i* theResult);
135
136     //----------------------------------------------------------------------------
137     virtual
138     void
139     SetEntity(Entity theEntity);
140
141     virtual
142     Entity
143     GetEntity();
144
145     TEntity
146     GetTEntity() const;
147
148     virtual
149     void
150     SetFieldName(const char* theFieldName);
151
152     virtual
153     char*
154     GetFieldName();
155
156     std::string
157     GetCFieldName() const;
158
159     virtual 
160     VISU::PField
161     GetField();
162
163     virtual
164     void 
165     SetTimeStampNumber(CORBA::Long theTimeStampNumber);
166
167     virtual
168     CORBA::Long
169     GetTimeStampNumber();
170
171     virtual
172     CORBA::Long
173     GetTimeStampNumberByIndex( CORBA::Long theIndex );
174
175     virtual
176     CORBA::Long
177     GetTimeStampIndexByNumber( CORBA::Long theNumber );
178
179     virtual 
180     VISU::PField
181     GetScalarField();
182
183     VISU::PMinMaxController
184     GetMinMaxController();
185
186     void
187     SetMinMaxController( const VISU::PMinMaxController& theController );
188
189     void
190     SetMinMaxController( ColoredPrs3d_i* theOrigin );
191
192     virtual
193     CORBA::Long
194     GetScalarTimeStampNumber() const;
195
196     virtual
197     VISU::ColoredPrs3dHolder::TimeStampsRange*
198     GetTimeStampsRange();
199
200     virtual 
201     CORBA::Boolean 
202     IsTimeStampFixed();
203
204     virtual
205     EPublishInStudyMode
206     GetPublishInStudyMode();
207
208     //----------------------------------------------------------------------------
209     virtual
210     CORBA::Long
211     GetScalarMode();
212
213     virtual
214     void 
215     SetScalarMode(CORBA::Long theScalarMode);
216
217     virtual
218     CORBA::Double 
219     GetMin();
220
221     virtual
222     CORBA::Double 
223     GetMax();
224
225     virtual
226     void
227     SetRange(CORBA::Double theMin, CORBA::Double theMax);
228
229     virtual
230     vtkFloatingPointType
231     GetComponentMin(vtkIdType theCompID) = 0;
232
233     virtual
234     vtkFloatingPointType
235     GetComponentMax(vtkIdType theCompID) = 0;
236
237     virtual
238     CORBA::Double 
239     GetSourceMin();
240
241     virtual
242     CORBA::Double 
243     GetSourceMax();
244
245     virtual 
246     void
247     SetSourceRange();
248
249     virtual
250     CORBA::Boolean
251     IsRangeFixed();
252
253     virtual 
254     void 
255     SetNbColors(CORBA::Long theNbColors);
256
257     virtual
258     CORBA::Long 
259     GetNbColors();
260
261     virtual
262     void
263     SetBarOrientation(VISU::ColoredPrs3dBase::Orientation theOrientation);
264
265     virtual 
266     VISU::ColoredPrs3dBase::Orientation 
267     GetBarOrientation();
268
269     virtual
270     void
271     SetPosition(CORBA::Double X, CORBA::Double Y);
272
273     virtual
274     CORBA::Double
275     GetPosX();
276
277     virtual
278     CORBA::Double
279     GetPosY();
280
281     virtual 
282     void
283     SetSize(CORBA::Double theWidth, CORBA::Double theHeight);
284     
285     virtual 
286     void
287     SetRatios(CORBA::Long theTitleSize, CORBA::Long theLabelSize, 
288               CORBA::Long theBarWidth, CORBA::Long theBarHeight);
289     
290     virtual 
291     CORBA::Double
292     GetWidth();
293
294     virtual
295     CORBA::Double
296     GetHeight();
297
298     virtual 
299     CORBA::Long
300     GetTitleSize();
301
302     virtual 
303     CORBA::Long
304     GetLabelSize();
305
306     virtual 
307     CORBA::Long
308     GetBarWidth();
309
310     virtual
311     CORBA::Long
312     GetBarHeight();
313
314     virtual 
315     void
316     SetLabels(CORBA::Long theNbLabels);
317
318     virtual
319     CORBA::Long
320     GetLabels();
321
322     virtual
323     void
324     SetLabelsFormat(const char* theFormat);
325
326     virtual
327     char* 
328     GetLabelsFormat();
329
330     virtual
331     void
332     SetTitle(const char* theTitle);
333
334     virtual
335     char* 
336     GetTitle();
337
338     std::string 
339     GetCTitle();
340
341     virtual
342     void
343     SetUnitsVisible(CORBA::Boolean isVisible);
344
345     virtual
346     CORBA::Boolean
347     IsUnitsVisible();
348
349     /*!  
350      * Set the visibility of a distribution curve.
351      * \param theIs is used to switch on/off the visibility of a distribution curve.
352      */
353     virtual void SetIsDistributionVisible(CORBA::Boolean theIs);
354     
355     //! Gets current visibility of a distribution curve
356     virtual CORBA::Boolean GetIsDistributionVisible();
357     
358     //! Gets current filtering by scalars mode
359     virtual CORBA::Boolean IsScalarFilterUsed();
360     
361     virtual void UseScalarFiltering( CORBA::Boolean theUseScalarFilter );
362
363     /*!
364      * Sets scalar range - min and max boundaries of the scalar bar.
365      * \param theMin  Min boundary of the scalar bar.
366      * \param theMax  Max boundary of the scalar bar.
367      * \param theIsFilter  if true then filter by scalars.
368      */
369     virtual
370     void
371     SetScalarFilterRange( CORBA::Double theMin, CORBA::Double theMax );
372
373     //----------------------------------------------------------------------------
374     virtual
375     CORBA::Double
376     GetScalarFilterMin();
377
378     //----------------------------------------------------------------------------
379     virtual
380     CORBA::Double
381     GetScalarFilterMax();
382
383     //----------------------------------------------------------------------------
384     //! Gets memory size actually used by the presentation (Mb).
385     virtual
386     CORBA::Float
387     GetMemorySize();
388
389     //----------------------------------------------------------------------------
390     //! Returns presentation input
391     VISU::ColoredPrs3dHolder::BasicInput*
392     GetBasicInput();
393
394     virtual
395     void
396     SetHolderEntry(const std::string& theEntry);
397
398     virtual
399     std::string
400     GetHolderEntry();
401
402     //! To keep restoring params till the explicit Restore() call
403     void
404     SaveRestoringState(SALOMEDS::SObject_ptr theSObject,
405                        const Storable::TRestoringMap& theMap);
406
407     //! To restore the presentation according to the saved state
408     void 
409     InitFromRestoringState();
410
411     //----------------------------------------------------------------------------
412     virtual 
413     const char* 
414     GetIconName() = 0;
415
416
417     //----------------------------------------------------------------------------
418     //! Sets initial source geometry
419     virtual
420     void
421     SetSourceGeometry()=0;
422
423     //! Add geometry of mesh as group. \retval the id of added group.
424     virtual 
425     void
426     AddMeshOnGroup(const char* theGroupName)=0;
427     
428     //! Removes all geometries.
429     virtual
430     void
431     RemoveAllGeom()=0;
432     
433     typedef std::string TGroupName;
434     typedef std::set<TGroupName> TGroupNames;
435     
436     const TGroupNames&
437     GetGroupNames();
438
439     //! Gets number of geometries
440     bool 
441     IsGroupsUsed();
442
443     //----------------------------------------------------------------------------
444   public:
445     /*!
446       Initlizes the in first time presentation
447     */
448     virtual
449     Storable* 
450     Create(const std::string& theMeshName, 
451            VISU::Entity theEntity,
452            const std::string& theFieldName, 
453            CORBA::Long theTimeStampNumber);
454
455     /*!
456       Retores state of the presentation
457     */
458     virtual 
459     Storable* 
460     Restore(SALOMEDS::SObject_ptr theSObject,
461             const Storable::TRestoringMap& theMap);
462
463     /*!
464       Writes persistent params of the presentation into the given stream
465     */
466     virtual 
467     void
468     ToStream(std::ostringstream& theStr);
469
470     /*!
471       Update state of the presentation according to the input.
472     */
473     virtual 
474     void
475     SameAs(const Prs3d_i* theOrigin);
476
477     virtual
478     void
479     UpdateActor(VISU_ActorBase* theActor);
480
481     virtual 
482     bool
483     IsBoldTitle();
484
485     virtual
486     void
487     SetBoldTitle(bool isBold);
488
489     virtual
490     bool
491     IsItalicTitle();
492
493     virtual
494     void
495     SetItalicTitle(bool isItalic);
496
497     virtual 
498     bool
499     IsShadowTitle();
500
501     virtual
502     void
503     SetShadowTitle(bool isShadow);
504
505     virtual 
506     int
507     GetTitFontType();
508
509     virtual
510     void
511     SetTitFontType(int theType);
512
513     virtual 
514     void
515     GetTitleColor(vtkFloatingPointType& theR, 
516                   vtkFloatingPointType& theG, 
517                   vtkFloatingPointType& theB);
518     
519     virtual
520     void
521     SetTitleColor(vtkFloatingPointType theR, 
522                   vtkFloatingPointType theG, 
523                   vtkFloatingPointType theB);    
524
525     virtual
526     bool
527     IsBoldLabel();
528
529     virtual
530     void
531     SetBoldLabel(bool isBold);
532
533     virtual
534     bool
535     IsItalicLabel();
536
537     virtual
538     void
539     SetItalicLabel(bool isItalic);
540
541     virtual
542     bool
543     IsShadowLabel();
544
545     virtual
546     void
547     SetShadowLabel(bool isShadow);
548
549     virtual 
550     int
551     GetLblFontType();
552
553     virtual
554     void
555     SetLblFontType(int theType);
556
557     virtual 
558     void
559     GetLabelColor(vtkFloatingPointType& theR, 
560                   vtkFloatingPointType& theG, 
561                   vtkFloatingPointType& theB);
562
563     virtual
564     void
565     SetLabelColor(vtkFloatingPointType theR, 
566                   vtkFloatingPointType theG, 
567                   vtkFloatingPointType theB);
568
569     virtual
570     void
571     SetMapScale(double theMapScale = 1.0);
572
573     VISU_ColoredPL* 
574     GetSpecificPL() const
575     { 
576       return myColoredPL; 
577     }
578     
579         virtual 
580     int
581     GetValLblFontType() const;
582
583     virtual 
584     void
585     SetValLblFontType( const int theType );
586
587     virtual 
588     double
589     GetValLblFontSize() const;
590
591     virtual 
592     void
593     SetValLblFontSize( const double theSize );
594
595     virtual 
596     bool
597     IsBoldValLbl() const;
598
599     virtual
600     void
601     SetBoldValLbl( const bool theVal );
602
603     virtual 
604     bool
605     IsItalicValLbl() const;
606
607     virtual
608     void
609     SetItalicValLbl( const bool theVal );
610
611     virtual 
612     bool
613     IsShadowValLbl() const;
614
615     virtual
616     void
617     SetShadowValLbl( const bool theVal );
618
619     virtual 
620     void
621     GetValLblFontColor( vtkFloatingPointType& theR, 
622                        vtkFloatingPointType& theG, 
623                        vtkFloatingPointType& theB ) const;
624
625     virtual
626     void
627     SetValLblFontColor( const vtkFloatingPointType theR, 
628                         const vtkFloatingPointType theG, 
629                         const vtkFloatingPointType theB );
630     
631     //----------------------------------------------------------------------------
632   protected:
633     /*!
634       Applyes basic input parameters to the presentation.
635       Returns true if all are right.
636     */
637     virtual 
638     bool 
639     SetInput(bool theReInit);
640
641     //! Restore input parameters if Apply function fails (redefines Prs3d::OnRestoreInput)
642     virtual 
643     void 
644     OnRestoreInput();
645
646     /*!
647       Checks whether it is possible to create presentation 
648       with the given basic parameters or not.
649     */
650     virtual 
651     bool 
652     CheckIsPossible() = 0;
653
654     /*!
655       Creates proper instance of VTK pipeline.
656     */
657     virtual
658     void 
659     CreatePipeLine(VISU_PipeLine* thePipeLine);
660
661     /*!
662       First checks whether corresponding VTK pipeline exists and create it if not. 
663       Then calls VISU_ColoredPrs3d_i::DoSetInput.
664       Returns true if during the call corresponding VTK pipeline was created,
665       false otherwise.
666     */
667     virtual 
668     bool
669     OnSetInput(bool theReInit);
670
671    /*!
672       Sets input data set according to basic input parameters -
673       Result, MeshName, Entity, FieldName and TimeStampNumber.
674     */
675     virtual 
676     void
677     DoSetInput(bool theIsInitilizePipe, bool theReInit) = 0;
678
679     /*! 
680       The enumeration allow to define what mode should be used for the presentation building.
681     */
682     enum EBuildMode {ECreateNew, ESameAs, ERestore};
683
684     /*! 
685       The enumeration allow to define what mode should be used for the presentation building.
686     */
687     Storable* 
688     Build(EBuildMode theBuildMode);
689
690     virtual
691     void
692     SetField(VISU::PField theField);
693
694     void
695     UseFixedRange(bool theUseFixedRange);
696
697     std::string 
698     GetScalarBarTitle();
699
700     //! Used in derived classes to initilize the IO for actors
701     virtual
702     std::string
703     GetActorEntry();
704
705     TGroupNames myGroupNames;
706     
707   private:
708     bool myIsRestored;
709     Storable::TRestoringMap myRestoringMap;
710     SALOMEDS::SObject_var myRestoringSObject;
711
712     // Decalare basic input parameters
713     VISU::Entity myEntity;
714     VISU::Entity myPreviousEntity;
715
716     std::string myFieldName;
717     std::string myPreviousFieldName;
718
719     CORBA::Long myTimeStampNumber;
720     CORBA::Long myPreviousTimeStampNumber;
721
722     boost::signalslib::connection myResultConnection;
723
724     bool myIsTimeStampFixed;
725
726     PField myField;
727     PMinMaxController myMinMaxController;
728     EPublishInStudyMode myPublishInStudyMode;
729
730     std::string myHolderEntry;
731
732     std::string myTitle;
733     std::string myScalarBarTitle;
734     bool        myIsUnits;
735
736     int myNumberOfLabels;
737     std::string myLabelsFormat;
738
739     VISU::ColoredPrs3dBase::Orientation myOrientation;
740     vtkFloatingPointType myPosition[2],
741                          myWidth, myHeight,
742                          myTitleSize, myLabelSize,
743                          myBarWidth, myBarHeight;
744
745     //Font management
746     bool myIsBoldTitle;
747     bool myIsItalicTitle;
748     bool myIsShadowTitle;
749     int  myTitFontType;
750     vtkFloatingPointType myTitleColor[3];
751
752     bool myIsBoldLabel;
753     bool myIsItalicLabel;
754     bool myIsShadowLabel;
755     int  myLblFontType;
756     vtkFloatingPointType myLabelColor[3];
757
758     VISU_ColoredPL* myColoredPL;
759     bool myIsFixedRange;
760
761     bool myIsDistributionVisible; // RKV
762
763     // Result labels 
764     int                  myValLblFontType;
765     double               myValLblFontSize;
766     bool                 myIsBoldValLbl;
767     bool                 myIsItalicValLbl;
768     bool                 myIsShadowValLbl;
769     vtkFloatingPointType myValLblFontColor[ 3 ];
770   };
771
772
773   //----------------------------------------------------------------------------
774   template<class TColoredPrs3d>
775   Storable* 
776   StorableEngine(SALOMEDS::SObject_ptr theSObject,
777                  const Storable::TRestoringMap& theMap,
778                  const std::string& thePrefix,
779                  CORBA::Boolean theIsMultiFile)
780   {
781     TColoredPrs3d* aColoredPrs3d = new TColoredPrs3d(ColoredPrs3d_i::EDoNotPublish);
782     return aColoredPrs3d->Restore(theSObject, theMap);
783   }
784
785
786   //----------------------------------------------------------------------------
787 }
788
789 #endif