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
24 // File : GEOMToolsGUI_1.cxx
25 // Author : Sergey ANIKIN
29 #include <PyConsole_Console.h>
31 #include "GEOMToolsGUI.h"
33 #include "GeometryGUI.h"
34 #include "GEOM_Displayer.h"
35 #include "GEOMToolsGUI_TransparencyDlg.h"
36 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
40 #include "SALOME_ListIO.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include <SVTK_ViewModel.h>
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_View.h>
47 #include <OCCViewer_ViewModel.h>
49 #include <SUIT_ViewManager.h>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_MessageBox.h>
56 #include <SalomeApp_Application.h>
57 #include <SalomeApp_Study.h>
58 #include <SalomeApp_Module.h>
60 #include <LightApp_SelectionMgr.h>
61 #include <LightApp_NameDlg.h>
63 #include "utilities.h"
66 #include <AIS_Drawer.hxx>
67 #include <Prs3d_IsoAspect.hxx>
68 #include <Prs3d_PointAspect.hxx>
69 #include <Graphic3d_AspectMarker3d.hxx>
72 #include <QColorDialog>
77 void GEOMToolsGUI::OnSettingsColor()
79 SUIT_Session* sess = SUIT_Session::session();
80 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
81 SUIT_Desktop* desk = sess->activeApplication()->desktop();
83 QColor anInitColor = resMgr->colorValue( "Geometry", "SettingsShadingColor", QColor( "yellow" ) );
85 QColor aDialogColor = QColorDialog::getColor(anInitColor, desk );
86 if( aDialogColor.isValid() )
88 QString type = desk->activeWindow()->getViewManager()->getType();
89 if( type != OCCViewer_Viewer::Type() && type != SVTK_Viewer::Type() )
90 MESSAGE("Settings Color is not supported for current Viewer");
92 resMgr->setValue( "Geometry", "SettingsShadingColor", aDialogColor );
96 void GEOMToolsGUI::OnSettingsIsos()
99 SUIT_Session* sess = SUIT_Session::session();
100 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
101 SUIT_Desktop* desk = sess->activeApplication()->desktop();
103 SUIT_ViewManager* vman = desk->activeWindow()->getViewManager();
104 QString type = vman->getType();
106 if ( type != OCCViewer_Viewer::Type() )
109 OCCViewer_Viewer* vm = (OCCViewer_Viewer*)vman->getViewModel();
110 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
112 int IsoU = resMgr->integerValue( "Geometry:SettingsIsoU", 1 );
113 int IsoV = resMgr->integerValue( "Geometry:SettingsIsoV", 1 );
115 ic->DefaultDrawer()->UIsoAspect()->SetNumber( IsoU );
116 ic->DefaultDrawer()->VIsoAspect()->SetNumber( IsoV );
118 GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(desk, tr("GEOM_MEN_ISOS"), TRUE);
120 NbIsosDlg->SpinBoxU->setValue(IsoU);
121 NbIsosDlg->SpinBoxV->setValue(IsoV);
123 if(NbIsosDlg->exec()) {
124 IsoU = NbIsosDlg->SpinBoxU->text().toInt();
125 IsoV = NbIsosDlg->SpinBoxV->text().toInt();
127 ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
128 ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
129 resMgr->setValue("Geometry:SettingsIsoU", isoU);
130 resMgr->setValue("Geometry:SettingsIsoV", isoV);
135 void GEOMToolsGUI::OnSettingsStep()
137 SUIT_Session* sess = SUIT_Session::session();
138 SUIT_ResourceMgr* resMgr = sess->resourceMgr();
140 double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100. );
142 Standard_Boolean res = false;
143 double dd = GEOMBase::Parameter( res, QString("%1").arg(step).toStdString().c_str(),
144 tr("GEOM_MEN_STEP_LABEL").toStdString().c_str(),
145 tr("GEOM_STEP_TITLE").toStdString().c_str(), 0.001, 10000.0, 3);
147 resMgr->setValue( "Geometry", "SettingsGeomStep", dd );
149 /* Emit signal to GeometryGUI_SpinBoxes */
150 getGeometryGUI()->EmitSignalDefaultStepValueChanged( dd );
153 sess->activeApplication()->putInfo(tr("GEOM_PRP_ABORT"));
156 void GEOMToolsGUI::OnRename()
158 SALOME_ListIO selected;
159 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
161 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
162 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
163 if ( aSelMgr && appStudy ) {
164 aSelMgr->selectedObjects( selected );
165 if ( !selected.IsEmpty() ) {
166 _PTR(Study) aStudy = appStudy->studyDS();
168 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
170 SUIT_MessageBox::warning ( app->desktop(),
171 QObject::tr("WRN_WARNING"),
172 QObject::tr("WRN_STUDY_LOCKED"),
173 QObject::tr("BUT_OK") );
177 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
178 Handle(SALOME_InteractiveObject) IObject = It.Value();
180 _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
181 _PTR(GenericAttribute) anAttr;
183 if( obj->FindAttribute(anAttr, "AttributeName") ) {
184 _PTR(AttributeName) aName (anAttr);
186 QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
187 if ( !newName.isEmpty() ) {
188 aName->SetValue( newName.toLatin1().constData() ); // rename the SObject
189 IObject->setName( newName.toLatin1() );// rename the InteractiveObject
190 // Rename the corresponding GEOM_Object
191 GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
192 if (!CORBA::is_nil( anObj ))
193 anObj->SetName( newName.toLatin1() );
194 (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
196 } // if ( name attribute )
203 app->updateActions(); //SRN: To update a Save button in the toolbar
206 void GEOMToolsGUI::OnCheckGeometry()
208 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
209 PyConsole_Console* pyConsole = app->pythonConsole();
212 pyConsole->exec("from GEOM_usinggeom import *");
215 void GEOMToolsGUI::OnColor()
217 SALOME_ListIO selected;
218 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
220 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
222 aSelMgr->selectedObjects( selected );
223 if ( !selected.IsEmpty() ) {
224 SUIT_ViewWindow* window = app->desktop()->activeWindow();
225 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
226 bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
228 SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
231 SVTK_View* aView = vtkVW->getView();
232 QColor initcolor = aView->GetColor( selected.First() );
233 QColor c = QColorDialog::getColor( QColor(), app->desktop() );
235 SUIT_OverrideCursor();
236 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
237 aView->SetColor( It.Value(), c );
242 Handle(AIS_InteractiveObject) io = GEOMBase::GetAIS( selected.First() );
243 if ( !io.IsNull() ) {
244 Quantity_Color aColor;
246 QColor initcolor( (int)( aColor.Red() * 255.0 ), (int)( aColor.Green() * 255.0 ), (int)( aColor.Blue() * 255.0 ) );
247 QColor c = QColorDialog::getColor( initcolor, app->desktop() );
249 SUIT_OverrideCursor();
250 aColor = Quantity_Color( c.red() / 255., c.green() / 255., c.blue() / 255., Quantity_TOC_RGB );
251 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
252 io = GEOMBase::GetAIS( It.Value(), true );
253 if ( !io.IsNull() ) {
254 // Set color for a point
255 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
256 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
257 Handle(AIS_Drawer) aCurDrawer = io->Attributes();
258 Handle(Prs3d_PointAspect) aCurPointAspect = aCurDrawer->PointAspect();
259 Quantity_Color aCurColor;
260 Standard_Real aCurScale;
261 Aspect_TypeOfMarker aCurTypeOfMarker;
262 aCurPointAspect->Aspect()->Values( aCurColor, aCurTypeOfMarker, aCurScale );
263 aCurDrawer->SetPointAspect( new Prs3d_PointAspect( aCurTypeOfMarker, aColor, aCurScale) );
264 ic->SetLocalAttributes(io, aCurDrawer);
266 io->SetColor( aColor );
267 if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
268 Handle(GEOM_AISShape)::DownCast( io )->SetShadingColor( aColor );
270 io->Redisplay( Standard_True );
274 } // first IO is not null
276 } // if ( selection not empty )
280 app->updateActions(); //SRN: To update a Save button in the toolbar
283 void GEOMToolsGUI::OnTransparency()
285 GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
289 void GEOMToolsGUI::OnNbIsos()
291 SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
292 bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
297 OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
298 Handle (AIS_InteractiveContext) ic = vm->getAISContext();
301 if ( ic->MoreCurrent() ) {
302 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
303 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
305 int UIso = CurDrawer->UIsoAspect()->Number();
306 int VIso = CurDrawer->VIsoAspect()->Number();
308 GEOMToolsGUI_NbIsosDlg * NbIsosDlg =
309 new GEOMToolsGUI_NbIsosDlg( SUIT_Session::session()->activeApplication()->desktop() );
311 NbIsosDlg->setU( UIso );
312 NbIsosDlg->setV( VIso );
314 if ( NbIsosDlg->exec() ) {
315 SUIT_OverrideCursor();
316 for(; ic->MoreCurrent(); ic->NextCurrent()) {
317 CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
318 Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
320 int nbUIso = NbIsosDlg->getU();
321 int nbVIso = NbIsosDlg->getV();
323 CurDrawer->SetUIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbUIso) );
324 CurDrawer->SetVIsoAspect( new Prs3d_IsoAspect(Quantity_NOC_GRAY75, Aspect_TOL_SOLID, 0.5 , nbVIso) );
326 ic->SetLocalAttributes(CurObject, CurDrawer);
327 ic->Redisplay(CurObject);
333 void GEOMToolsGUI::OnOpen()
336 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
337 _PTR(Study) aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
339 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
340 Handle(SALOME_InteractiveObject) anIObject;
341 for(;It.More();It.Next()) {
342 anIObject = It.Value();
343 _PTR(SObject) obj ( aStudy->FindObjectID(anIObject->getEntry()) );
344 _PTR(AttributePersistentRef) aPersist;
345 _PTR(AttributeIOR) anIOR;
347 // this SObject may be GEOM module root SObject
348 _PTR(ChildIterator) anIter ( aStudy->NewChildIterator() );
349 _PTR(GenericAttribute) anAttr;
350 bool useSubItems = false;
351 while (anIter->More() && !useSubItems) {
352 _PTR(SObject) subobj ( anIter->Value() );
353 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
360 obj->FindAttribute(anAttr, "AttributePersistentRef");
362 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
363 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
364 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
365 _PTR(SComponent) FComp ( obj->GetFatherComponent() );
367 if (FComp->FindAttribute(anAttr, "AttributeName")) {
368 _PTR(AttributeName) aName ( anAttr );
369 QString compName = QAD_Application::getDesktop()->getComponentName(aName->Value().c_str());
370 // parent->loadComponentData(parent->getComponentName(aName->Value()));
371 Engines::Component_var comp ;
372 if ( compName.compare("SUPERV") == 0 ) {
373 comp = QAD_Application::getDesktop()->getEngine( "SuperVisionContainer", compName) ;
376 comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", compName);
377 if ( comp->_is_nil() )
378 comp = QAD_Application::getDesktop()->getEngine( "FactoryServerPy", compName);
381 if (!CORBA::is_nil(comp)) {
382 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
383 if (!CORBA::is_nil(driver)) {
384 SALOMEDS::StudyBuilder_var B = dynamic_cast<SALOMEDS_Study*>(aStudy.get())->GetStudy()->NewBuilder();
385 if (!CORBA::is_nil(B)) {
386 B->LoadWith(FComp,driver);
392 MESSAGE("loadComponentData(): Driver is null");
397 MESSAGE("loadComponentData(): Engine is null");
401 // Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
402 // if (!CORBA::is_nil(comp)) {
403 // SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
404 // SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
405 // SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
406 // if (!CORBA::is_nil(SC))
407 // aStudyBuilder->LoadWith(SC,driver);
411 MESSAGE("Component is null");
416 obj.reset( anIter->Value() );
426 void GEOMToolsGUI::OnSelectOnly(int mode)
428 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
430 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
431 GEOM_Displayer aDisp (appStudy);
432 aDisp.GlobalSelection(mode);
433 getGeometryGUI()->setLocalSelectionMode(mode);