1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2004 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GEOMToolsGUI_1.cxx
23 // Author : Sergey ANIKIN, , Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26 #include <PyConsole_Console.h>
28 #include "GEOMToolsGUI.h"
30 #include <GeometryGUI.h>
31 #include <GEOM_Displayer.h>
32 #include "GEOMToolsGUI_TransparencyDlg.h"
33 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
37 #include <SALOME_ListIO.hxx>
38 #include <SALOME_ListIteratorOfListIO.hxx>
40 #include <SVTK_ViewModel.h>
41 #include <SVTK_ViewWindow.h>
42 #include <SVTK_View.h>
44 #include <OCCViewer_ViewModel.h>
46 #include <SUIT_ViewManager.h>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_ResourceMgr.h>
49 #include <SUIT_Session.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
53 #include <SalomeApp_Application.h>
54 #include <SalomeApp_Study.h>
55 #include <SalomeApp_Module.h>
57 #include <LightApp_SelectionMgr.h>
58 #include <LightApp_NameDlg.h>
60 #include "utilities.h"
63 #include <AIS_Drawer.hxx>
64 #include <Prs3d_IsoAspect.hxx>
65 #include <Prs3d_PointAspect.hxx>
66 #include <Graphic3d_AspectMarker3d.hxx>
69 #include <QColorDialog>
74 void GEOMToolsGUI::OnSettingsColor()
76 SUIT_Session* sess = SUIT_Session::session();
77 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
78 SUIT_Desktop* desk = sess->activeApplication()->desktop();
80 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
82 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
83 if( aDialogColor.isValid() )
85 QString type = desk->activeWindow()->getViewManager()->getType();
86 if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
87 MESSAGE("Settings Color is not supported for current Viewer");
89 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
93 void GEOMToolsGUI::OnSettingsIsos()
96 SUIT_Session* sess = SUIT_Session::session();
97 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
98 SUIT_Desktop* desk = sess->activeApplication()->desktop();
100 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
101 QString type = vman->getType();
103 if ( type != OCCViewer_Viewer::Type() )
106 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
107 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
109 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
110 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
112 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
113 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
115 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
117 NbIsosDlg->SpinBoxU->setValue(IsoU);
118 NbIsosDlg->SpinBoxV->setValue(IsoV);
120 if(NbIsosDlg->exec()) {
121 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
122 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
124 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
125 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
126 resMgr->setValue("Geometry:SettingsIsoU", isoU);
127 resMgr->setValue("Geometry:SettingsIsoV", isoV);
132 void GEOMToolsGUI::OnSettingsStep()
134 SUIT_Session* sess = SUIT_Session::session();
135 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
137 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
139 Standard_Boolean res = false;
140 double dd = GEOMBase::Parameter( res, QString("%1").arg(step).toLatin1().constData(),
141 tr("GEOM_MEN_STEP_LABEL").toLatin1().constData(),
142 tr("GEOM_STEP_TITLE").toLatin1().constData(), 0.001, 10000.0, 3);
144 resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
146 /* Emit signal to GeometryGUI_SpinBoxes */
147 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
150 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
153 void GEOMToolsGUI::OnRename()
155 SALOME_ListIO selected;
156 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
158 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
159 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
160 if ( aSelMgr && appStudy ) {
161 aSelMgr->selectedObjects( selected );
162 if ( !selected.IsEmpty() ) {
163 _PTR(Study) aStudy = appStudy->studyDS();
165 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
167 SUIT_MessageBox::warning ( app->desktop(),
168 QObject::tr("WRN_WARNING"),
169 QObject::tr("WRN_STUDY_LOCKED"),
170 QObject::tr("BUT_OK") );
174 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
175 Handle(SALOME_InteractiveObject) IObject = It.Value();
177 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
178 _PTR(GenericAttribute) anAttr;
180 if( obj->FindAttribute(anAttr, "AttributeName") ) {
181 _PTR(AttributeName) aName (anAttr);
183 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
184 if ( !newName.isEmpty() ) {
185 aName->SetValue( newName.toLatin1().constData() ); // rename the SObject
186 IObject->setName( newName.toLatin1() );// rename the InteractiveObject
187 // Rename the corresponding GEOM_Object
188 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
189 if (!CORBA::is_nil( anObj ))
190 anObj->SetName( newName.toLatin1() );
191 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
193 } // if ( name attribute )
200 app->updateActions(); //SRN: To update a Save button in the toolbar
203 void GEOMToolsGUI::OnCheckGeometry()
205 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
206 PyConsole_Console* pyConsole = app->pythonConsole();
209 pyConsole->exec("from GEOM_usinggeom import *");
212 void GEOMToolsGUI::OnColor()
214 SALOME_ListIO selected;
215 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
217 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
219 aSelMgr->selectedObjects( selected );
220 if ( !selected.IsEmpty() ) {
221 SUIT_ViewWindow* window = app->desktop()->activeWindow();
222 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
223 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
225 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
228 SVTK_View* aView = vtkVW->getView();
229 QColor initcolor = aView->GetColor( selected.First() );
230 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
232 SUIT_OverrideCursor();
233 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
234 aView->SetColor( It.Value(), c );
239 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
240 if ( !io.IsNull() ) {
241 Quantity_Color aColor;
243 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
244 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
246 SUIT_OverrideCursor();
247 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
248 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
249 io = GEOMBase::GetAIS( It.Value(), true );
250 if ( !io.IsNull() ) {
251 // Set color for a point
252 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
253 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
254 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
255 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
256 Quantity_Color aCurColor;
257 Standard_Real aCurScale;
258 Aspect_TypeOfMarker aCurTypeOfMarker;
259 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
260 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
261 ic->SetLocalAttributes(io, aCurDrawer);
263 io->SetColor( aColor );
264 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
265 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
267 io->Redisplay( Standard_True );
271 } // first IO is not null
273 } // if ( selection not empty )
277 app->updateActions(); //SRN: To update a Save button in the toolbar
280 void GEOMToolsGUI::OnTransparency()
282 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
286 void GEOMToolsGUI::OnNbIsos()
288 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
289 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
294 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
295 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
298 if ( ic->MoreCurrent() ) {
299 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
300 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
302 int UIso = CurDrawer->UIsoAspect()->Number();
303 int VIso = CurDrawer->VIsoAspect()->Number();
305 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
306 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
308 NbIsosDlg->setU( UIso );
309 NbIsosDlg->setV( VIso );
311 if ( NbIsosDlg->exec() ) {
312 SUIT_OverrideCursor();
313 for(; ic->MoreCurrent(); ic->NextCurrent()) {
314 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
315 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
317 int nbUIso = NbIsosDlg->getU();
318 int nbVIso = NbIsosDlg->getV();
320 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
321 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
323 ic->SetLocalAttributes(CurObject, CurDrawer);
324 ic->Redisplay(CurObject);
330 void GEOMToolsGUI::OnOpen()
333 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
334 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
336 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
337 Handle(SALOME_InteractiveObject) anIObject;
338 for(;It.More();It.Next()) {
339 anIObject = It.Value();
340 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
341 _PTR(AttributePersistentRef) aPersist;
342 _PTR(AttributeIOR) anIOR;
344 // this SObject may be GEOM module root SObject
345 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
346 _PTR(GenericAttribute) anAttr;
347 bool useSubItems = false;
348 while (anIter->More() && !useSubItems) {
349 _PTR(SObject) subobj ( anIter->Value() );
350 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
357 obj->FindAttribute(anAttr, "AttributePersistentRef");
359 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
360 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
361 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
362 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
364 if (FComp->FindAttribute(anAttr, "AttributeName")) {
365 _PTR(AttributeName) aName ( anAttr );
366 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
367 // parent->loadComponentData(parent->getComponentName(aName->Value()));
368 Engines::Component_var comp ;
369 if ( compName.compare("SUPERV") == 0 ) {
370 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
373 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
374 if ( comp->_is_nil() )
375 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
378 if (!CORBA::is_nil(comp)) {
379 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
380 if (!CORBA::is_nil(driver)) {
381 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
382 if (!CORBA::is_nil(B)) {
383 B->LoadWith(FComp,driver);
389 MESSAGE("loadComponentData(): Driver is null");
394 MESSAGE("loadComponentData(): Engine is null");
398 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
399 // if (!CORBA::is_nil(comp)) {
400 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
401 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
402 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
403 // if (!CORBA::is_nil(SC))
404 // aStudyBuilder->LoadWith(SC,driver);
408 MESSAGE("Component is null");
413 obj.reset( anIter->Value() );
423 void GEOMToolsGUI::OnSelectOnly(int mode)
425 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
427 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
428 GEOM_Displayer aDisp (appStudy);
429 aDisp.GlobalSelection(mode);
430 getGeometryGUI()->setLocalSelectionMode(mode);