-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <SUIT_ShortcutMgr.h>
#include <SUIT_Desktop.h>
#include <SUIT_TreeModel.h>
+#include <SUIT_Session.h>
#ifndef DISABLE_SALOMEOBJECT
#include <SALOME_ListIO.hxx>
#include <QVariant>
#include <QString>
#include <QStringList>
+#include <QAction>
#include <iostream>
myDisplay( -1 ),
myErase( -1 ),
myDisplayOnly( -1 ),
- myEraseAll( -1 )
+ myEraseAll( -1 ),
+ myIsFirstActivate( true )
{
}
m->registerColumn( getApp()->objectBrowser(), EntryCol, LightApp_DataObject::EntryId );
treeModel->setAppropriate( EntryCol, Qtx::Toggled );
}*/
+
+ if ( myIsFirstActivate ) {
+ updateModuleVisibilityState();
+ myIsFirstActivate = false;
+ }
+
return res;
}
return CAM_Module::deactivateModule( study );
}
+/*! Redefined to reset internal flags valid for study instance */
+void LightApp_Module::studyClosed( SUIT_Study* theStudy )
+{
+ CAM_Module::studyClosed( theStudy );
+
+ myIsFirstActivate = true;
+
+ LightApp_Application* app = dynamic_cast<LightApp_Application*>(application());
+ if ( app ) {
+ SUIT_DataBrowser* ob = app->objectBrowser();
+ if ( ob && ob->model() )
+ disconnect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
+ this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) );
+ }
+}
+
/*!NOT IMPLEMENTED*/
void LightApp_Module::MenuItem()
{
return false;
}
+/*!
+ Update visibility state for data objects
+*/
+void LightApp_Module::updateModuleVisibilityState()
+{
+ // update visibility state of objects
+ LightApp_Application* app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
+ if ( !app ) return;
+
+ SUIT_DataBrowser* ob = app->objectBrowser();
+ if ( !ob || !ob->model() ) return;
+ // connect to click on item
+ connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ),
+ this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection );
-int LightApp_Module::createMenu( const QString& subMenu, const int menu, const int id, const int group, const int idx )
-{
- return CAM_Module::createMenu( subMenu, menu, id, group, idx );
-}
-int LightApp_Module::createMenu( const QString& subMenu, const QString& menu, const int id, const int group, const int idx )
-{
- return CAM_Module::createMenu( subMenu, menu, id, group, idx );
-}
-int LightApp_Module::createMenu( const int id, const int menu, const int group, const int idx )
-{
- return CAM_Module::createMenu( id, menu, group, idx );
-}
-int LightApp_Module::createMenu( const int id, const QString& menu, const int group, const int idx )
-{
- return CAM_Module::createMenu( id, menu, group, idx );
-}
-int LightApp_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
-{
- return CAM_Module::createMenu( a, menu, id, group, idx );
+ SUIT_DataObject* rootObj = ob->root();
+ if ( !rootObj ) return;
+
+ DataObjectList listObj = rootObj->children( true );
+
+ SUIT_ViewModel* vmod = 0;
+ if ( SUIT_ViewManager* vman = app->activeViewManager() )
+ vmod = vman->getViewModel();
+ app->updateVisibilityState( listObj, vmod );
}
-int LightApp_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
+
+/*!
+ * \brief Virtual public slot
+ *
+ * This method is called after the object inserted into data view to update their visibility state
+ * This is default implementation
+ */
+void LightApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn )
{
- return CAM_Module::createMenu( a, menu, id, group, idx );
+ if ( !isActiveModule() ) return;
+
+ // change visibility of object
+ if ( !theObject || theColumn != SUIT_DataObject::VisibilityId ) return;
+
+ LightApp_Study* study = dynamic_cast<LightApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
+ if ( !study ) return;
+
+ LightApp_DataObject* lo = dynamic_cast<LightApp_DataObject*>( theObject );
+ if ( !lo ) return;
+
+ // detect action index (from LightApp level)
+ int id = -1;
+
+ if ( study->visibilityState( lo->entry() ) == Qtx::ShownState )
+ id = myErase;
+ else if ( study->visibilityState( lo->entry() ) == Qtx::HiddenState )
+ id = myDisplay;
+
+ if ( id != -1 )
+ startOperation( id );
}