* Add tab "General" in Preferences window.
* Add algorithm to update displaying elements depending of settings.
* Update opening file algorithm to activating parts depending of settings.
* Update activating part algorithm to display elements depending of settings.
* Update activating part algorithm to display elements depending of sub elements.
* Update the documentation.
SHAPER preferences contains the following tabs:
+- :ref:`general_preferences`;
- :ref:`visualization_preferences`;
- :ref:`plugins_preferences`;
- :ref:`shortcuts_preferences`;
- :ref:`sketch_preferences`.
- :ref:`viewer_preferences`.
-Visualization tab is activated by default when **Preferences** dialog box is opened in the active SHAPER module.
+General tab is activated by default when **Preferences** dialog box is opened in the active SHAPER module.
Other tabs are activated by click on tab header.
+.. _general_preferences:
+
+General tab
+^^^^^^^^^^^
+
+This tab defines what parts to be activated and what elements to be visible after opening a study or a script.
+
+.. figure:: /images/general_preferences.png
+ :align: center
+
+ **Preferences**: General tab
+
+**Input fields**:
+- **Activate** relates to activation of part when opening a HDF document. Its could be one of the following:
+
+ - \93Last part\94 \96 activate last part in the document (**default value**);
+ - \93All parts\94 \96 activate all parts within the document;
+ - \93No activation\94 \96 do not activate any part.
+
+- **Display** in "Opening a study". It specifies the shapes, which should be visualized when activating a part. It could be one of the following:
+
+ - \93As stored in HDF\94 \96 display only the shapes visible before the document is saved (**default value**);
+ - \93Last item in each folder\94 \96 show only the last result in each folder of the part: Constructions, Results, Groups, Fields;
+ - \93All items\94 \96 show all shapes from each folder;
+ - \93No visualization\94 \96 do not display any shape.
+
+- **Display** in "Launching a python script". It specifies the shapes, which should be visualized when loading a script using "File -> Load Script..." menu. It could be one of the following:
+
+ - \93Last item in each folder\94 \96 show only the last result in each folder of the part: Constructions, Results, Groups, Fields;
+ - \93All items\94 \96 show all shapes from each folder(**default value**);
+ - \93No visualization\94 \96 do not display any shape.
+
.. _visualization_preferences:
Visualization tab
const QString ModuleBase_Preferences::VIEWER_SECTION = "Viewer";
const QString ModuleBase_Preferences::MENU_SECTION = "Menu";
+const QString ModuleBase_Preferences::GENERAL_SECTION = "General";
SUIT_ResourceMgr* ModuleBase_Preferences::myResourceMgr = 0;
void ModuleBase_Preferences::createEditContent(ModuleBase_IPrefMgr* thePref, int thePage)
{
thePref->prefMgr()->setItemIcon(thePage, QIcon(":pictures/module.png"));
+ createGeneralTab(thePref, thePage);
createCustomPage(thePref, thePage);
}
}
}
+void ModuleBase_Preferences::createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId)
+{
+ int generalTab = thePref->addPreference(QObject::tr("General"), thePageId,
+ SUIT_PreferenceMgr::Auto, QString(), QString());
+ thePref->setItemProperty("columns", 2, generalTab);
+
+ QStringList actItemList;
+ actItemList << QObject::tr("Last part")
+ << QObject::tr("All parts")
+ << QObject::tr("No activation");
+
+ QList<QVariant> actIdList;
+ actIdList << 0 << 1 << 2;
+
+ // Group related to opening a study
+ int group = thePref->addPreference(QObject::tr("Opening a study"), generalTab,
+ SUIT_PreferenceMgr::Auto, QString(), QString());
+
+ int actId = thePref->addPreference(QObject::tr("Activate"), group, SUIT_PreferenceMgr::Selector,
+ ModuleBase_Preferences::GENERAL_SECTION,
+ "part_activation_study");
+ thePref->setItemProperty("strings", actItemList, actId);
+ thePref->setItemProperty("indexes", actIdList, actId);
+
+ QStringList visuItemList;
+ visuItemList << QObject::tr("As stored in HDF")
+ << QObject::tr("Last item in each folder")
+ << QObject::tr("All items")
+ << QObject::tr("No visualization");
+
+ QList<QVariant> visuIdList;
+ visuIdList << 0 << 1 << 2 << 3;
+
+ int visuId = thePref->addPreference(QObject::tr("Display"), group, SUIT_PreferenceMgr::Selector,
+ ModuleBase_Preferences::GENERAL_SECTION,
+ "part_visualization_study");
+ thePref->setItemProperty("strings", visuItemList, visuId);
+ thePref->setItemProperty("indexes", visuIdList, visuId);
+
+ // Group related to running a python script
+ group = thePref->addPreference(QObject::tr("Launching a python script"), generalTab,
+ SUIT_PreferenceMgr::Auto, QString(), QString());
+
+ visuItemList.clear();
+ visuItemList << QObject::tr("Last item in each folder")
+ << QObject::tr("All items")
+ << QObject::tr("No visualization");
+
+ visuIdList.clear();
+ visuIdList << 0 << 1 << 2;
+
+ visuId = thePref->addPreference(QObject::tr("Display"), group, SUIT_PreferenceMgr::Selector,
+ ModuleBase_Preferences::GENERAL_SECTION,
+ "part_visualization_script");
+ thePref->setItemProperty("strings", visuItemList, visuId);
+ thePref->setItemProperty("indexes", visuIdList, visuId);
+}
+
void ModuleBase_Preferences::createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId)
{
SUIT_ResourceMgr* aResMgr = ModuleBase_Preferences::resourceMgr();
/// Name of preferences of menu section
static const QString MENU_SECTION;
+ /// Name of preferences of general section
+ static const QString GENERAL_SECTION;
+
/// Shows a dialog box to edit preferences
/// \param theModified a list of modified preferences
static bool editPreferences(ModuleBase_Prefs& theModified);
/// Set default values to the Config_PropManager properties
static void resetConfig();
+ /// Creates a content for General tab, which defines behavior of loading parts and displaying shapes
+ static void createGeneralTab(ModuleBase_IPrefMgr* thePref, int thePageId);
+
/// Creates content of preferences editing widget
static void createCustomPage(ModuleBase_IPrefMgr* thePref, int thePageId);
#include <XGUI_DataModel.h>
#include <XGUI_OperationMgr.h>
#include <XGUI_ObjectsBrowser.h>
+#include <XGUI_Tools.h>
#include <XGUI_ViewerProxy.h>
#include <Events_Loop.h>
void PartSet_MenuMgr::activatePart(ResultPartPtr thePart) const
{
bool isFirstLoad = !thePart->partDoc().get();
+ ModuleBase_Tools::blockUpdateViewer(true);
thePart->activate();
if (isFirstLoad) {
XGUI_Workshop* aWorkshop = myModule->getWorkshop();
XGUI_ObjectsBrowser* aObjBrowser = aWorkshop->objectBrowser();
+ XGUI_Tools::setDisplaying(thePart);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ aObjBrowser->onSelectionChanged();
DocumentPtr aDoc = thePart->partDoc();
std::list<bool> aStates;
aDoc->restoreNodesState(aStates);
aObjBrowser->setStateForDoc(aDoc, aStates);
}
+ ModuleBase_Tools::blockUpdateViewer(false);
}
void PartSet_MenuMgr::onActivateAllParts()
<parameter name="PartSet" value="%SHAPER_ROOT_DIR%/share/salome/resources/shaper"/>
<parameter name="XGUI" value="%SHAPER_ROOT_DIR%/share/salome/resources/shaper"/>
</section>
+ <section name="General">
+ <!-- Common settings of part's activation and visualization -->
+ <parameter name="part_activation_study" value="0"/>
+ <parameter name="part_visualization_study" value="0"/>
+ <parameter name="part_visualization_script" value="1"/>
+ </section>
<section name="Viewer" >
<!-- Viewer preferences -->
<parameter name="face-selection" value="true" />
<parameter name="language" value="en"/>
<parameter name="locale" value="true"/>
</section>
+ <section name="General">
+ <!-- Common settings of part's activation and visualization -->
+ <parameter name="part_activation_study" value="0"/>
+ <parameter name="part_visualization_study" value="0"/>
+ <parameter name="part_visualization_script" value="1"/>
+ </section>
<section name="Viewer" >
<!-- Viewer preferences -->
<parameter name="background" value="bt=2;fn=;tm=0;ts=false;c1=#cddbff;c2=#698fff;gt=1;gr=" />
#include "ModuleBase_IWorkshop.h"
#include "ModuleBase_Tools.h"
+#include "ModuleBase_Preferences.h"
#include <TopoDS_Shape.hxx>
#include <ModelAPI_Object.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultField.h>
#include <Events_InfoMessage.h>
+#include <SUIT_ResourceMgr.h>
+
#include <GeomAPI_Shape.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
}
}
+// Set displaying status to every element on group
+static void setDisplayingByLoop(DocumentPtr theDoc, int theSize,
+ std::string theGroup, bool theDisplayFromScript)
+{
+ int aDisplayingId = -1;
+ if (theDisplayFromScript) {
+ aDisplayingId = ModuleBase_Preferences::resourceMgr()->integerValue("General",
+ "part_visualization_script", -1);
+ // Increase ID to prevert using "As stored in HDF"
+ ++aDisplayingId;
+ }
+ else {
+ aDisplayingId = ModuleBase_Preferences::resourceMgr()->integerValue("General",
+ "part_visualization_study", -1);
+
+ // if chosen "As stored in HDF" then don't change displaying
+ if (aDisplayingId == 0)
+ return;
+ }
+
+ for (int anIndex = theSize - 1; anIndex >= 0; --anIndex) {
+ ObjectPtr anObject = theDoc->object(theGroup, anIndex);
+ anObject->setDisplayed((aDisplayingId == 1 && anIndex == theSize - 1) || aDisplayingId == 2);
+ }
+}
+
+void setDisplaying(ResultPartPtr thePart, bool theDisplayFromScript)
+{
+ DocumentPtr aDoc = thePart->partDoc();
+ int aConstructionSize = aDoc->size(ModelAPI_ResultConstruction::group());
+ int aGroupSize = aDoc->size(ModelAPI_ResultGroup::group());
+ int aFieldSize = aDoc->size(ModelAPI_ResultField::group());
+ int aResultSize = aDoc->size(ModelAPI_ResultBody::group());
+ setDisplayingByLoop(aDoc, aConstructionSize,
+ ModelAPI_ResultConstruction::group(), theDisplayFromScript);
+ setDisplayingByLoop(aDoc, aGroupSize, ModelAPI_ResultGroup::group(), theDisplayFromScript);
+ setDisplayingByLoop(aDoc, aFieldSize, ModelAPI_ResultField::group(), theDisplayFromScript);
+ setDisplayingByLoop(aDoc, aResultSize, ModelAPI_ResultBody::group(), theDisplayFromScript);
+}
+
}
#include <QRect>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultPart.h>
#include <ModuleBase_ViewerPrs.h>
#include <ModuleBase_Definitions.h>
/// Removes files and directory where they are located
void removeTemporaryFiles(const std::string& theDirectory,
const std::list<std::string>& theFiles);
+
+/// Set displaying status for elements from part depending on the settings
+/// \param thePart a pointer of part
+XGUI_EXPORT void setDisplaying(ResultPartPtr thePart, bool theDisplayFromScript = false);
};
#endif
myDisplayer->deactivateObjects(anObjects, theUpdateViewer);
}
}
+
+ SUIT_Application * app = SUIT_Session::session()->activeApplication();
+
+ QVariant aVar = app->property("IsLoadedScript");
+
+ if (!aVar.isNull() && aVar.toBool()) {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
+ if (aSize > 0) {
+ ObjectPtr anPartObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1);
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anPartObject);
+ XGUI_Tools::setDisplaying(aPart, true);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
+ }
}
//******************************************************
}
#endif
+ int anActivationId =
+ ModuleBase_Preferences::resourceMgr()->integerValue("General", "part_activation_study", -1);
+ int aSize = aRootDoc->size(ModelAPI_ResultPart::group());
+
+ if (anActivationId == 0 && aSize > 0) {
+ ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), aSize - 1);
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
+ if (aPart.get()) {
+ aPart->activate();
+ XGUI_Tools::setDisplaying(aPart);
+ }
+ }
+ else if (anActivationId == 1) {
+ for (int anIndex = 0; anIndex < aSize; ++anIndex) {
+ ObjectPtr anObject = aRootDoc->object(ModelAPI_ResultPart::group(), anIndex);
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
+ if (aPart.get()) {
+ aPart->activate();
+ XGUI_Tools::setDisplaying(aPart);
+
+ if (anIndex < aSize - 1) {
+ SessionPtr aMgr = ModelAPI_Session::get();
+ aMgr->startOperation("Activation");
+ aMgr->setActiveDocument(aMgr->moduleDocument());
+ aMgr->finishOperation();
+ updateCommandStatus();
+ viewer()->update();
+ }
+ }
+ }
+ }
QApplication::restoreOverrideCursor();
}
#include <ModuleBase_Tools.h>
#include <ModuleBase_WidgetSelector.h>
+#ifdef HAVE_SALOME
+#include <SUIT_Application.h>
+#include <SUIT_Session.h>
+#endif
+
#include "XGUI_ActionsMgr.h"
#include "XGUI_Displayer.h"
#include "XGUI_ErrorMgr.h"
void XGUI_WorkshopListener::
onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
{
+ SUIT_Application * app = SUIT_Session::session()->activeApplication();
+
+ QVariant aVar = app->property("IsLoadedScript");
+
std::set<ObjectPtr> anObjects = theMsg->objects();
std::set<ObjectPtr>::const_iterator aIt;
#ifdef DEBUG_FEATURE_CREATED
//bool aHasPart = false;
bool aDisplayed = false;
- for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
- ObjectPtr anObject = *aIt;
+ if (aVar.isNull() || !aVar.toBool()) {
+ for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
+ ObjectPtr anObject = *aIt;
#ifdef DEBUG_RESULT_COMPSOLID
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aRes.get()) {
- ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
- if (aCompSolidRes.get()) {
- qDebug(QString("COMPSOLID, numberOfSubs = %1")
- .arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aRes.get()) {
+ ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
+ if (aCompSolidRes.get()) {
+ qDebug(QString("COMPSOLID, numberOfSubs = %1")
+ .arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
+ }
+ if (ModelAPI_Tools::compSolidOwner(aRes))
+ qDebug("COMPSOLID sub-object");
}
- if (ModelAPI_Tools::compSolidOwner(aRes))
- qDebug("COMPSOLID sub-object");
- }
#endif
- // the validity of the data should be checked here in order to avoid display of the objects,
- // which were created, then deleted, but flush for the creation event happens after that
- // we should not display disabled objects
- bool aHide = !anObject->data()->isValid() ||
- anObject->isDisabled() ||
- !anObject->isDisplayed();
- if (!aHide) { // check that this is not hidden result
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- aHide = aRes && aRes->isConcealed();
- // Hide the presentation with an empty shape. But isDisplayed state of the object should not
- // be changed to the object becomes visible when the shape becomes not empty
- if (!aHide && aRes.get())
- aHide = !aRes->shape().get() || aRes->shape()->isNull();
- }
- if (!aHide) {
- // setDisplayed has to be called in order to synchronize internal state of the object
- // with list of displayed objects
- if (myWorkshop->module()->canDisplayObject(anObject)) {
- anObject->setDisplayed(true);
- aDisplayed = displayObject(anObject);
- } else
- anObject->setDisplayed(false);
+
+ ResultBodyPtr aRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
+
+ if (aRes.get() && aRes->numberOfSubs() > 0)
+ for (int anIndex = 0; anIndex < aRes->numberOfSubs(); ++anIndex)
+ setDisplayed(aRes->subResult(anIndex), aDisplayed);
+ else
+ setDisplayed(anObject, aDisplayed);
}
}
-
MAYBE_UNUSED bool isCustomized = customizeFeature(anObjects, aDisplayed);
//if (myObjectBrowser)
{
return myWorkshop;
}
+
+
+void XGUI_WorkshopListener::setDisplayed(ObjectPtr theObject, bool& theDisplayed)
+{
+ // the validity of the data should be checked here in order to avoid display of the objects,
+ // which were created, then deleted, but flush for the creation event happens after that
+ // we should not display disabled objects
+ bool aHide = !theObject->data()->isValid() ||
+ theObject->isDisabled() ||
+ !theObject->isDisplayed();
+ if (!aHide) { // check that this is not hidden result
+ ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ aHide = aRes && aRes->isConcealed();
+ // Hide the presentation with an empty shape. But isDisplayed state of the object should not
+ // be changed to the object becomes visible when the shape becomes not empty
+ if (!aHide && aRes.get())
+ aHide = !aRes->shape().get() || aRes->shape()->isNull();
+ }
+ if (!aHide) {
+ // setDisplayed has to be called in order to synchronize internal state of the object
+ // with list of displayed objects
+ if (myWorkshop->module()->canDisplayObject(theObject)) {
+ theObject->setDisplayed(true);
+ theDisplayed = displayObject(theObject);
+ }
+ else
+ theObject->setDisplayed(false);
+ }
+}
XGUI_Workshop* workshop() const;
private:
+
+ void setDisplayed(ObjectPtr theObject, bool& theDisplayed);
+
XGUI_Workshop* myWorkshop; // the current workshop
bool myUpdatePrefs;