Salome HOME
IPAL21035 It's impossible to hide scalar bar for gauss points
[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( const VisuGUI* theModule, QWidget* theParent ) :
51   VisuGUI_Panel( tr( "WINDOW_TITLE" ), theModule, theParent, ApplyBtn | CloseBtn | HelpBtn ),
52   myActor( 0 )
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 QtxDoubleSpinBox( 0.0, 90.0, 10.0, myGrp );
62
63   myFeatureEdgesCB = new QCheckBox( tr( "SHOW_FEATURE_EDGES" ), myGrp );
64   myBoundaryEdgesCB = new QCheckBox( tr( "SHOW_BOUNDARY_EDGES" ), myGrp );
65   myManifoldEdgesCB = new QCheckBox( tr( "SHOW_MANIFOLD_EDGES" ), myGrp );
66   myNonManifoldEdgesCB = new QCheckBox( tr( "SHOW_NON_MANIFOLD_EDGES" ), myGrp );
67
68   //myColoringCB = new QCheckBox( tr( "FEATURE_EDGES_COLORING" ), myGrp );
69
70   aLayout->addWidget( anAngleLbl, 0, 0 );
71   aLayout->addWidget( myAngleSpinBox, 0, 1 );
72   aLayout->addWidget( myFeatureEdgesCB, 1, 0, 1, 2 );
73   aLayout->addWidget( myBoundaryEdgesCB, 2, 0, 1, 2 );
74   aLayout->addWidget( myManifoldEdgesCB, 3, 0, 1, 2 );
75   aLayout->addWidget( myNonManifoldEdgesCB, 4, 0, 1, 2 );
76   //aLayout->addWidget( myColoringCB, 5, 0, 1, 2 );
77
78   aTopLayout->addWidget( myGrp );
79
80   SalomeApp_Application* anApp =
81     dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
82   LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
83   connect( aSelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionEvent() ) );
84 }
85
86 VisuGUI_FeatureEdgesPanel::~VisuGUI_FeatureEdgesPanel()
87 {
88 }
89
90 void VisuGUI_FeatureEdgesPanel::showEvent( QShowEvent* theEvent )
91 {
92   onSelectionEvent();
93
94   VisuGUI_Panel::showEvent(theEvent);
95 }
96
97 VISU_Actor* VisuGUI_FeatureEdgesPanel::getSelectedActor() const
98 {
99   SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>( myModule );
100   if( !aViewWindow )
101     return 0;
102
103   _PTR(SObject) aSObject;
104   VISU::Prs3d_i* aPrs3d = 0;
105   Handle(SALOME_InteractiveObject) anIO;
106
107   VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects( myModule );
108   if( aSelectionInfo.size() != 1 )
109     return 0;
110
111   VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
112   VISU::TObjectInfo anObjectInfo = aSelectionItem.myObjectInfo;
113   aPrs3d = GetPrs3dFromBase( anObjectInfo.myBase );
114   if( !aPrs3d )
115     return 0;
116
117   anIO = aSelectionItem.myIO;
118   aSObject = anObjectInfo.mySObject;
119   
120   VISU_Actor* anActor =
121     VISU::FindActor( VISU::GetAppStudy( myModule ), aViewWindow, aSObject->GetID().c_str() );
122
123   return anActor;
124 }
125
126 void VisuGUI_FeatureEdgesPanel::onSelectionEvent()
127 {
128   myActor = getSelectedActor();
129   bool anIsSelected = myActor && myActor->IsFeatureEdgesAllowed();
130
131   myGrp->setEnabled( anIsSelected );
132   myApply->setEnabled( anIsSelected );
133
134   if( !anIsSelected )
135     return;
136
137   if( !myActor->IsFeatureEdgesAllowed() )
138     return;
139
140   float anAngle = myActor->GetFeatureEdgesAngle();
141
142   bool anIsFeatureEdges = false,
143        anIsBoundaryEdges = false,
144        anIsManifoldEdges = false,
145        anIsNonManifoldEdges = false;
146   myActor->GetFeatureEdgesFlags( anIsFeatureEdges,
147                                  anIsBoundaryEdges,
148                                  anIsManifoldEdges,
149                                  anIsNonManifoldEdges );
150
151   float aColoring = myActor->GetFeatureEdgesColoring();
152
153   myAngleSpinBox->setValue( anAngle );
154   myFeatureEdgesCB->setChecked( anIsFeatureEdges );
155   myBoundaryEdgesCB->setChecked( anIsBoundaryEdges );
156   myManifoldEdgesCB->setChecked( anIsManifoldEdges );
157   myNonManifoldEdgesCB->setChecked( anIsNonManifoldEdges );
158   //myColoringCB->setChecked( aColoring );
159 }
160
161 void VisuGUI_FeatureEdgesPanel::onApply()
162 {
163   if( myActor )
164   {
165     myActor->SetFeatureEdgesAngle( myAngleSpinBox->value() );
166     myActor->SetFeatureEdgesFlags( myFeatureEdgesCB->isChecked(),
167                                    myBoundaryEdgesCB->isChecked(),
168                                    myManifoldEdgesCB->isChecked(),
169                                    myNonManifoldEdgesCB->isChecked() );
170     //myActor->SetFeatureEdgesColoring( myColoringCB->isChecked() );
171     myActor->Update();
172   }
173
174   VisuGUI_Panel::onApply();
175 }
176
177 void VisuGUI_FeatureEdgesPanel::onClose()
178 {
179   close();
180   VisuGUI_Panel::onClose();
181 }
182
183 void VisuGUI_FeatureEdgesPanel::onHelp()
184 {
185   QString aHelpFileName = "feature_edges_page.html";
186   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
187   if (app)
188     app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
189   else {
190     QString platform;
191 #ifdef WIN32
192     platform = "winapplication";
193 #else
194     platform = "application";
195 #endif
196     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
197                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
198                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName) );
199   }
200
201   VisuGUI_Panel::onHelp();
202 }
203
204 void VisuGUI_FeatureEdgesPanel::keyPressEvent( QKeyEvent* e )
205 {
206   VisuGUI_Panel::keyPressEvent( e );
207   if ( e->isAccepted() )
208     return;
209
210   if ( e->key() == Qt::Key_F1 )
211     {
212       e->accept();
213       onHelp();
214     }
215 }