Salome HOME
Update copyright information
[modules/visu.git] / src / VISUGUI / VisuGUI_FeatureEdgesPanel.cxx
1 // Copyright (C) 2007-2012  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 VISUGUI : GUI of VISU component
21 //  File   : VisuGUI_FeatureEdgesPanel.cxx
22 //  Author : Oleg Uvarov
23 //  Module : VISU
24 //
25 #include "VisuGUI_FeatureEdgesPanel.h"
26
27 #include "VisuGUI.h"
28 #include "VisuGUI_Tools.h"
29 #include "VisuGUI_ViewTools.h"
30
31 #include <QCheckBox>
32 #include <QGroupBox>
33 #include <QKeyEvent>
34 #include <QLabel>
35 #include <QLayout>
36 #include <QPushButton>
37
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ResourceMgr.h>
41
42 #include <SalomeApp_Application.h>
43 #include <SalomeApp_DoubleSpinBox.h>
44
45 #include <LightApp_SelectionMgr.h>
46
47 VisuGUI_FeatureEdgesPanel::VisuGUI_FeatureEdgesPanel( VisuGUI* theModule, QWidget* theParent ) :
48   VisuGUI_Panel( tr( "WINDOW_TITLE" ), theModule, theParent, ApplyBtn | CloseBtn | HelpBtn ),
49   myActor( 0 )
50 {
51   setWindowTitle( tr( "WINDOW_TITLE" ) );
52   setObjectName( tr( "WINDOW_TITLE" ) );
53
54   QVBoxLayout* aTopLayout = new QVBoxLayout( mainFrame() );
55   myGrp = new QGroupBox( tr( "FEATURE_EDGES_PROPERTIES" ), mainFrame() );
56
57   QGridLayout* aLayout = new QGridLayout( myGrp );
58   aLayout->setAlignment( Qt::AlignTop );
59
60   QLabel* anAngleLbl = new QLabel( tr( "FEATURE_EDGES_ANGLE" ), myGrp );
61   myAngleSpinBox = new SalomeApp_DoubleSpinBox( myGrp );
62   VISU::initSpinBox( myAngleSpinBox, 0.0, 90.0, 10.0, "angle_precision" );
63
64   myFeatureEdgesCB = new QCheckBox( tr( "SHOW_FEATURE_EDGES" ), myGrp );
65   myBoundaryEdgesCB = new QCheckBox( tr( "SHOW_BOUNDARY_EDGES" ), myGrp );
66   myManifoldEdgesCB = new QCheckBox( tr( "SHOW_MANIFOLD_EDGES" ), myGrp );
67   myNonManifoldEdgesCB = new QCheckBox( tr( "SHOW_NON_MANIFOLD_EDGES" ), myGrp );
68
69   //myColoringCB = new QCheckBox( tr( "FEATURE_EDGES_COLORING" ), myGrp );
70
71   aLayout->addWidget( anAngleLbl, 0, 0 );
72   aLayout->addWidget( myAngleSpinBox, 0, 1 );
73   aLayout->addWidget( myFeatureEdgesCB, 1, 0, 1, 2 );
74   aLayout->addWidget( myBoundaryEdgesCB, 2, 0, 1, 2 );
75   aLayout->addWidget( myManifoldEdgesCB, 3, 0, 1, 2 );
76   aLayout->addWidget( myNonManifoldEdgesCB, 4, 0, 1, 2 );
77   //aLayout->addWidget( myColoringCB, 5, 0, 1, 2 );
78
79   aTopLayout->addWidget( myGrp );
80
81   connect( myModule->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
82            this,                               SLOT( onSelectionEvent() ) );
83 }
84
85 VisuGUI_FeatureEdgesPanel::~VisuGUI_FeatureEdgesPanel()
86 {
87 }
88
89 void VisuGUI_FeatureEdgesPanel::showEvent( QShowEvent* theEvent )
90 {
91   onSelectionEvent();
92
93   VisuGUI_Panel::showEvent(theEvent);
94 }
95
96 VISU_Actor* VisuGUI_FeatureEdgesPanel::getSelectedActor() const
97 {
98   SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>( myModule );
99   if( !aViewWindow )
100     return 0;
101
102   _PTR(SObject) aSObject;
103   VISU::Prs3d_i* aPrs3d = 0;
104   Handle(SALOME_InteractiveObject) anIO;
105
106   VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects( myModule );
107   if( aSelectionInfo.size() != 1 )
108     return 0;
109
110   VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
111   VISU::TObjectInfo anObjectInfo = aSelectionItem.myObjectInfo;
112   aPrs3d = GetPrs3dFromBase( anObjectInfo.myBase );
113   if( !aPrs3d )
114     return 0;
115
116   anIO = aSelectionItem.myIO;
117   aSObject = anObjectInfo.mySObject;
118   
119   VISU_Actor* anActor =
120     VISU::FindActor( VISU::GetAppStudy( myModule ), aViewWindow, aSObject->GetID().c_str() );
121
122   return anActor;
123 }
124
125 void VisuGUI_FeatureEdgesPanel::onSelectionEvent()
126 {
127   myActor = getSelectedActor();
128   bool anIsSelected = myActor && myActor->IsFeatureEdgesAllowed();
129
130   myGrp->setEnabled( anIsSelected );
131   myApply->setEnabled( anIsSelected );
132
133   if( !anIsSelected )
134     return;
135
136   if( !myActor->IsFeatureEdgesAllowed() )
137     return;
138
139   float anAngle = myActor->GetFeatureEdgesAngle();
140
141   bool anIsFeatureEdges = false,
142        anIsBoundaryEdges = false,
143        anIsManifoldEdges = false,
144        anIsNonManifoldEdges = false;
145   myActor->GetFeatureEdgesFlags( anIsFeatureEdges,
146                                  anIsBoundaryEdges,
147                                  anIsManifoldEdges,
148                                  anIsNonManifoldEdges );
149
150   //float aColoring = myActor->GetFeatureEdgesColoring();
151
152   myAngleSpinBox->setValue( anAngle );
153   myFeatureEdgesCB->setChecked( anIsFeatureEdges );
154   myBoundaryEdgesCB->setChecked( anIsBoundaryEdges );
155   myManifoldEdgesCB->setChecked( anIsManifoldEdges );
156   myNonManifoldEdgesCB->setChecked( anIsNonManifoldEdges );
157   //myColoringCB->setChecked( aColoring );
158 }
159
160 void VisuGUI_FeatureEdgesPanel::onApply()
161 {
162   if( myActor )
163   {
164     myActor->SetFeatureEdgesAngle( myAngleSpinBox->value() );
165     myActor->SetFeatureEdgesFlags( myFeatureEdgesCB->isChecked(),
166                                    myBoundaryEdgesCB->isChecked(),
167                                    myManifoldEdgesCB->isChecked(),
168                                    myNonManifoldEdgesCB->isChecked() );
169     //myActor->SetFeatureEdgesColoring( myColoringCB->isChecked() );
170     myActor->Update();
171   }
172
173   VisuGUI_Panel::onApply();
174 }
175
176 void VisuGUI_FeatureEdgesPanel::onClose()
177 {
178   //  hide();
179   VisuGUI_Panel::onClose();
180 }
181
182 void VisuGUI_FeatureEdgesPanel::onHelp()
183 {
184   QString aHelpFileName = "feature_edges_page.html";
185   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
186   if (app)
187     app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
188   else {
189     QString platform;
190 #ifdef WIN32
191     platform = "winapplication";
192 #else
193     platform = "application";
194 #endif
195     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
196                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
197                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
198   }
199
200   VisuGUI_Panel::onHelp();
201 }
202
203 void VisuGUI_FeatureEdgesPanel::keyPressEvent( QKeyEvent* e )
204 {
205   VisuGUI_Panel::keyPressEvent( e );
206   if ( e->isAccepted() )
207     return;
208
209   if ( e->key() == Qt::Key_F1 )
210     {
211       e->accept();
212       onHelp();
213     }
214 }
215
216 void VisuGUI_FeatureEdgesPanel::onModuleActivated()
217 {
218   disconnect( myModule->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
219               this,                               SLOT( onSelectionEvent() ) );
220   connect( myModule->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
221            this,                               SLOT( onSelectionEvent() ) );
222   VisuGUI_Panel::onModuleActivated();
223 }
224
225 void VisuGUI_FeatureEdgesPanel::onModuleDeactivated()
226 {
227   disconnect( myModule->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
228               this,                               SLOT( onSelectionEvent() ) );
229   VisuGUI_Panel::onModuleDeactivated();
230 }