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