Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_Prs3dUtils.cc
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  VISU OBJECT : interactive object for VISU entities implementation
21 //  File   : VISU_Prs3dUtils.cc
22 //  Author : Alexey PETROV
23 //  Module : VISU
24 //
25 #include "VISU_Prs3dUtils.hh"
26 #include "SalomeApp_Study.h"
27 #include "SALOME_Event.h"
28
29
30 namespace VISU
31 {
32   //----------------------------------------------------------------------------
33   TSetModified
34   ::TSetModified(VISU::Prs3d_i* thePrs3d):
35     myPrs3d(thePrs3d)
36   {
37     this->Modified();
38   }
39
40
41   //----------------------------------------------------------------------------
42   TSetModified
43   ::~TSetModified()
44   {
45     struct TEvent: public SALOME_Event
46     {
47       VISU::TSetModified* mySetModified;
48       TEvent(VISU::TSetModified* theSetModified):
49         mySetModified(theSetModified)
50       {}
51     
52       virtual
53       void
54       Execute()
55       {
56         VISU::Prs3d_i* aPrs3d = mySetModified->myPrs3d;
57
58         if(!aPrs3d || aPrs3d->GetActorEntry() == "")
59           return;
60         
61         if(aPrs3d->GetMTime() > mySetModified->GetMTime()){
62           if(SalomeApp_Study* aStudy = aPrs3d->GetGUIStudy())
63             aStudy->Modified();
64         }
65       }
66     };
67
68     ProcessVoidEvent(new TEvent(this));
69   }
70
71   //----------------------------------------------------------------------------
72
73   std::string ToFormat( const int thePrec )
74   {
75     // "%-#6.3g"
76     char str[ 255 ];
77     sprintf( str, "%%-#.%dg", thePrec );
78     return str;
79   }
80
81   //----------------------------------------------------------------------------
82
83   int ToPrecision( const char* theFormat )
84   {
85     int N = strlen( theFormat );
86     int k = -1;
87     char str[ 255 ];
88     bool isOk = false;
89     for ( int i = 0; i < N; i++ )
90     {
91       if ( theFormat[ i ] ==  '.' )
92         k = 0;
93       else if ( theFormat[ i ] == 'g' )
94       {
95         str[ k ] = 0;
96         isOk = true;
97         break;
98       }
99       else if ( k >= 0 )
100         str[ k++ ] = theFormat[ i ];
101     }
102
103     int res = 0;
104     if ( isOk )
105       res = atoi( str );
106
107     return res;
108   }
109 };
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126