#include <ModelAPI_Tools.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Folder.h>
#include <ModelGeomAlgo_Point2D.h>
}
void checkObjects(const QObjectPtrList& theObjects, bool& hasResult, bool& hasFeature,
- bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory)
+ bool& hasParameter, bool& hasCompositeOwner, bool& hasResultInHistory,
+ bool& hasFolder)
{
hasResult = false;
hasFeature = false;
hasParameter = false;
hasCompositeOwner = false;
hasResultInHistory = false;
+ hasFolder = false;
foreach(ObjectPtr aObj, theObjects) {
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aObj);
ResultParameterPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aResult);
hasResult |= (aResult.get() != NULL);
hasFeature |= (aFeature.get() != NULL);
+ hasFolder |= (aFolder.get() != NULL);
hasParameter |= (aConstruction.get() != NULL);
if (hasFeature)
hasCompositeOwner |= (ModelAPI_Tools::compositeOwner(aFeature) != NULL);
hasResultInHistory = aFeature.get() && aFeature->isInHistory();
}
- if (hasFeature && hasResult && hasParameter && hasCompositeOwner)
+ if (hasFeature && hasResult && hasParameter && hasCompositeOwner && hasFeature)
break;
}
}
/// \param hasParameter will be set to true if list contains Parameter objects
/// \param hasCompositeOwner will be set to true if list contains Sub-Feature objects
/// \param hasResultInHistory will be set to true if one of result is in history
+/// \param hasFolder will be set to true if one of folder is in the list
MODULEBASE_EXPORT void checkObjects(const QObjectPtrList& theObjects, bool& hasResult,
bool& hasFeature, bool& hasParameter, bool& hasCompositeOwner,
- bool& hasResultInHistory);
+ bool& hasResultInHistory, bool& hasFolder);
/// Sets the default coeffient into the driver calculated accordingly the shape type.
/// It provides 1.e-4 for results of construction type
bool hasParameter = false;
bool hasCompositeOwner = false;
bool hasResultInHistory = false;
+ bool hasFolder = false;
ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
- hasCompositeOwner, hasResultInHistory);
+ hasCompositeOwner, hasResultInHistory, hasFolder);
ModuleBase_Operation* aCurrentOp = myWorkshop->currentOperation();
if (aSelected == 1) {
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultField.h>
+#include "ModelAPI_Folder.h"
#include <Config_DataModelReader.h>
XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
: QObject(theParent),
myWorkshop(theParent),
- mySeparator(0)
+ mySeparator1(0), mySeparator2(0)
{
}
aDesktop);
addAction("WIREFRAME_CMD", aAction);
- mySeparator = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
- mySeparator->setSeparator(true);
+ mySeparator1 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
+ mySeparator1->setSeparator(true);
+
+ mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
+ mySeparator2->setSeparator(true);
//mySelectActions = new QActionGroup(this);
//mySelectActions->setExclusive(true);
addAction("TINSPECTOR_VIEW", aAction);
#endif
+ // Features folders actions
+ aAction = ModuleBase_Tools::createAction(QIcon(),
+ tr("Insert a folder before"), aDesktop);
+ addAction("INSERT_FOLDER_CMD", aAction);
+
+ aAction = ModuleBase_Tools::createAction(QIcon(),
+ tr("Move into the previous folder"), aDesktop);
+ addAction("ADD_TO_FOLDER_BEFORE_CMD", aAction);
+
+ aAction = ModuleBase_Tools::createAction(QIcon(),
+ tr("Move into the next folder"), aDesktop);
+ addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
+
buildObjBrowserMenu();
buildViewerMenu();
}
bool hasParameter = false;
bool hasCompositeOwner = false;
bool hasResultInHistory = false;
+ bool hasFolder = false;
ModuleBase_Tools::checkObjects(aObjects, hasResult, hasFeature, hasParameter,
- hasCompositeOwner, hasResultInHistory);
+ hasCompositeOwner, hasResultInHistory, hasFolder);
//Process Feature
- if (aSelected == 1) {
+ if (aSelected == 1) { // single selection
ObjectPtr aObject = aObjects.first();
if (aObject) {
if (hasResult && myWorkshop->canBeShaded(aObject)) {
(hasFeature || hasParameter));
}
}
- } else {
+ // end single selection
+ } else { // multiselection
// parameter is commented because the actions are not in the list of result parameter actions
if (hasResult /*&& (!hasParameter)*/) {
action("SHOW_CMD")->setEnabled(true);
action("SHADING_CMD")->setEnabled(true);
action("WIREFRAME_CMD")->setEnabled(true);
}
- }
+ } // end multiselection
+
+ // Check folder management commands state if only features are selected
+ if ((!hasResult) && hasFeature && (!hasParameter) && (!hasCompositeOwner) &&
+ (!hasResultInHistory) && (!hasFolder)) {
+ QModelIndexList aIndexes = aSelMgr->selection()->selectedIndexes();
+ QModelIndex aFirstIdx = aIndexes.first();
+ QModelIndex aLastIdx = aIndexes.last();
+ QModelIndex aParentIdx = aFirstIdx.parent();
+
+ if (aParentIdx == aLastIdx.parent()) {
+ // if all selected are from the same level
+ XGUI_DataModel* aModel = myWorkshop->objectBrowser()->dataModel();
+ ObjectPtr aDataObj = aModel->object(aParentIdx);
+
+ ObjectPtr aPrevObj;
+ if (aFirstIdx.row() > 0) {
+ QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
+ aPrevObj = aModel->object(aPrevIdx);
+ }
+
+ ObjectPtr aNextObj;
+ if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
+ QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
+ aNextObj = aModel->object(aNextIdx);
+ }
+
+ bool isPrevFolder = (aPrevObj.get() && (aPrevObj->groupName() == ModelAPI_Folder::group()));
+ bool isNextFolder = (aNextObj.get() && (aNextObj->groupName() == ModelAPI_Folder::group()));
+ bool isInFolder = (aDataObj.get() && (aDataObj->groupName() == ModelAPI_Folder::group()));
+ bool isOutsideFolder = hasFeature && (!isInFolder);
+
+ action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
+ action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
+ action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
+ }
+ } // end folder management commands
+
bool allActive = true;
foreach( ObjectPtr aObject, aObjects )
if( aMgr->activeDocument() != aObject->document() ) {
action("SHOW_RESULTS_CMD")->setEnabled(hasFeature);
action("SHOW_FEATURE_CMD")->setEnabled(hasResult && hasResultInHistory);
- }
+ } // end selection processing
// Show/Hide command has to be disabled for objects from non active document
bool aDeactivate = false;
aList.append(action("SHOW_CMD"));
aList.append(action("HIDE_CMD"));
aList.append(action("SHOW_ONLY_CMD"));
- aList.append(mySeparator);
+ aList.append(mySeparator1);
aList.append(action("RENAME_CMD"));
aList.append(action("COLOR_CMD"));
aList.append(action("DEFLECTION_CMD"));
aList.clear();
aList.append(action("WIREFRAME_CMD"));
aList.append(action("SHADING_CMD"));
- aList.append(mySeparator); // this separator is not shown as this action is added after show only
+ aList.append(mySeparator1); // this separator is not shown as this action is added after show only
// qt list container contains only one instance of the same action
aList.append(action("SHOW_CMD"));
aList.append(action("HIDE_CMD"));
aList.append(action("SHOW_ONLY_CMD"));
- aList.append(mySeparator);
+ aList.append(mySeparator2);
aList.append(action("RENAME_CMD"));
aList.append(action("COLOR_CMD"));
aList.append(action("DEFLECTION_CMD"));
aList.append(action("RENAME_CMD"));
aList.append(action("SHOW_RESULTS_CMD"));
aList.append(action("MOVE_CMD"));
- aList.append(mySeparator);
+ aList.append(mySeparator1);
+ aList.append(action("INSERT_FOLDER_CMD"));
+ aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
+ aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
+ aList.append(mySeparator2);
aList.append(action("CLEAN_HISTORY_CMD"));
aList.append(action("DELETE_CMD"));
myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
aList.clear();
aList.append(action("RENAME_CMD"));
- aList.append(mySeparator);
+ aList.append(mySeparator1);
aList.append(action("CLEAN_HISTORY_CMD"));
aList.append(action("DELETE_CMD"));
myObjBrowserMenus[ModelAPI_ResultParameter::group()] = aList;
//-------------------------------------
+
+ aList.clear();
+ aList.append(action("DELETE_CMD"));
+ myObjBrowserMenus[ModelAPI_Folder::group()] = aList;
+
}
void XGUI_ContextMenuMgr::buildViewerMenu()
// Result construction menu
aList.append(action("HIDE_CMD"));
aList.append(action("SHOW_ONLY_CMD"));
- aList.append(mySeparator);
+ aList.append(mySeparator1);
aList.append(action("COLOR_CMD"));
aList.append(action("DEFLECTION_CMD"));
#ifdef USE_TRANSPARENCY
aList.clear();
aList.append(action("WIREFRAME_CMD"));
aList.append(action("SHADING_CMD"));
- aList.append(mySeparator);
+ aList.append(mySeparator1);
aList.append(action("HIDE_CMD"));
aList.append(action("SHOW_ONLY_CMD"));
- aList.append(mySeparator);
+ aList.append(mySeparator2);
aList.append(action("COLOR_CMD"));
aList.append(action("DEFLECTION_CMD"));
#ifdef USE_TRANSPARENCY
} else if (aSelected > 1) {
aActions.append(action("WIREFRAME_CMD"));
aActions.append(action("SHADING_CMD"));
- aActions.append(mySeparator);
+ aActions.append(mySeparator1);
aActions.append(action("SHOW_CMD"));
aActions.append(action("HIDE_CMD"));
aActions.append(action("SHOW_ONLY_CMD"));
- aActions.append(mySeparator);
+ aActions.append(mySeparator2);
//aActions.append(action("MOVE_CMD"));
aActions.append(action("COLOR_CMD"));
aActions.append(action("DEFLECTION_CMD"));
//QActionGroup* mySelectActions;
- QAction* mySeparator;
+ QAction* mySeparator1;
+ QAction* mySeparator2;
};
#endif
#include <ModelAPI_ResultCompSolid.h>
#include <ModelAPI_ResultField.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_Folder.h>
#include <Config_FeatureMessage.h>
#include <Config_DataModelReader.h>
// Insert new object
int aRow = aRootDoc->size(aObjType) - 1;
if (aRow != -1) {
- if (aObjType == aRootType) {
+ if ((aObjType == aRootType) || (aObjType == ModelAPI_Folder::group())) {
insertRow(aRow + aNbFolders + 1);
} else {
int aFolderId = myXMLReader->rootFolderId(aObjType);
}
}
}
- int aRow = aDoc->index(aObject);
+ int aRow = aDoc->index(aObject, true);
if (aRow != -1) {
int aNbSubFolders = foldersCount(aDoc.get());
- if (aObjType == aSubType) {
+ if ((aObjType == aSubType) || (aObjType == ModelAPI_Folder::group())) {
// List of objects under document root
insertRow(aRow + aNbSubFolders, aDocRoot);
} else {
{
std::string aType = theObject->groupName();
DocumentPtr aDoc = theObject->document();
- int aRow = aDoc->index(theObject);
+ int aRow = aDoc->index(theObject, true);
if (aRow == -1) {
// it could be a part of complex object
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
}
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
- if (aDoc == aRootDoc && myXMLReader->rootType() == aType) {
+ if (aDoc == aRootDoc &&
+ ((myXMLReader->rootType() == aType) || (aType == ModelAPI_Folder::group()))) {
// The object from root document
aRow += foldersCount();
- } else if (myXMLReader->subType() == aType) {
+ } else if ((myXMLReader->subType() == aType) || (aType == ModelAPI_Folder::group())) {
// The object from sub document
aRow += foldersCount(aDoc.get());
}
}
}
} else {
- ModelAPI_Object* aObj =
- dynamic_cast<ModelAPI_Object*>((ModelAPI_Entity*)theIndex.internalPointer());
+ ObjectPtr aObj = object(theIndex);
if (aObj) {
switch (theRole) {
case Qt::DisplayRole:
{
if (aObj->groupName() == ModelAPI_ResultParameter::group()) {
- ModelAPI_ResultParameter* aParam = dynamic_cast<ModelAPI_ResultParameter*>(aObj);
+ ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObj);
AttributeDoublePtr aValueAttribute =
aParam->data()->real(ModelAPI_ResultParameter::VALUE());
QString aVal = QString::number(aValueAttribute->value());
}
QString aSuffix;
if (aObj->groupName() == myXMLReader->subType()) {
- ResultPartPtr aPartRes = getPartResult(aObj);
+ ResultPartPtr aPartRes = getPartResult(aObj.get());
if (aPartRes.get()) {
if (aPartRes->partDoc().get() == NULL)
aSuffix = " (Not loaded)";
return aObj->data()->name().c_str() + aSuffix;
}
case Qt::DecorationRole:
- return ModuleBase_IconFactory::get()->getIcon(object(theIndex));
+ {
+ if (aObj->groupName() == ModelAPI_Folder::group())
+ return QIcon(":pictures/features_folder.png");
+ else
+ return ModuleBase_IconFactory::get()->getIcon(aObj);
+ }
}
} else {
switch (theRole) {
int aNbItems = 0;
std::string aType = myXMLReader->rootType();
if (!aType.empty())
- aNbItems = aRootDoc->size(aType);
+ aNbItems = aRootDoc->size(aType, true);
return aNbFolders + aNbItems;
}
int aNbSubItems = 0;
std::string aSubType = myXMLReader->subType();
if (!aSubType.empty())
- aNbSubItems = aSubDoc->size(aSubType);
+ aNbSubItems = aSubDoc->size(aSubType, true);
return aNbSubItems + aNbSubFolders;
} else {
// Check for composite object
else { // return object under root index
std::string aType = myXMLReader->rootType();
int aObjId = theRow - aNbFolders;
- if (aObjId < aRootDoc->size(aType)) {
- ObjectPtr aObj = aRootDoc->object(aType, aObjId);
+ if (aObjId < aRootDoc->size(aType, true)) {
+ ObjectPtr aObj = aRootDoc->object(aType, aObjId, true);
aIndex = objectIndex(aObj, theColumn);
}
}
if (aId == 0) { // return object index inside of first level of folders
std::string aType = myXMLReader->rootFolderType(aParentPos);
if (theRow < aRootDoc->size(aType)) {
- ObjectPtr aObj = aRootDoc->object(aType, theRow);
+ ObjectPtr aObj = aRootDoc->object(aType, theRow, true);
aIndex = objectIndex(aObj, theColumn);
}
} else {
} else {
// this is an object under sub document root
std::string aType = myXMLReader->subType();
- ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
+ ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders, true);
aIndex = objectIndex(aObj, theColumn);
}
} else {
DocumentPtr aRootDoc = aSession->moduleDocument();
DocumentPtr aSubDoc = aObj->document();
if (aSubDoc == aRootDoc) {
- if (aType == myXMLReader->rootType())
+ if ((aType == myXMLReader->rootType()) || (aType == ModelAPI_Folder::group()))
return QModelIndex();
else {
// return first level of folder index
return createIndex(aFolderId, 1, (void*)Q_NULLPTR);
}
} else {
- if (aType == myXMLReader->subType())
+ if ((aType == myXMLReader->subType()) || (aType == ModelAPI_Folder::group()))
return findDocumentRootIndex(aSubDoc.get());
else {
// return first level of folder index
ObjectPtr aObj;
ResultPartPtr aPartRes;
for (int i = 0; i < aNb; i++) {
- aObj = aRootDoc->object(ModelAPI_Feature::group(), i);
+ aObj = aRootDoc->object(ModelAPI_Feature::group(), i, true);
aPartRes = getPartResult(aObj.get());
if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
int aRow = i;
setViewerSelectionMode(TopAbs_EDGE);
} else if (theId == "SELECT_FACE_CMD") {
setViewerSelectionMode(TopAbs_FACE);
+ } else if (theId == "INSERT_FOLDER_CMD") {
+ insertFeatureFolder();
+ } else if (theId == "ADD_TO_FOLDER_BEFORE_CMD") {
+ insertToFolderBefore();
+ } else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
+ insertToFolderAfter();
} else if (theId == "SELECT_RESULT_CMD") {
//setViewerSelectionMode(-1);
//IMP: an attempt to use result selection with other selection modes
bool hasParameter = false;
bool hasCompositeOwner = false;
bool hasResultInHistory = false;
+ bool hasFolder = false;
ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter, hasCompositeOwner,
- hasResultInHistory);
- if (!(hasFeature || hasParameter))
+ hasResultInHistory, hasFolder);
+ if (!(hasFeature || hasParameter || hasFolder))
return;
// delete objects
objectBrowser()->blockSignals(aBlocked);
}
}
+
+void XGUI_Workshop::insertFeatureFolder()
+{
+ QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+ if (aObjects.isEmpty())
+ return;
+ ObjectPtr aObj = aObjects.first();
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature.get() == NULL)
+ return;
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->activeDocument();
+
+ aMgr->startOperation();
+ aDoc->addFolder(aFeature);
+ aMgr->finishOperation();
+}
+
+void XGUI_Workshop::insertToFolderBefore()
+{
+ QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+ if (aObjects.isEmpty())
+ return;
+}
+
+void XGUI_Workshop::insertToFolderAfter()
+{
+ QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+ if (aObjects.isEmpty())
+ return;
+}
/// Display results from a group
void displayGroupResults(DocumentPtr theDoc, std::string theGroup);
+ /// Insert folder object before currently selected feature
+ void insertFeatureFolder();
+
+ /// Insert an object to a folder above
+ void insertToFolderBefore();
+
+ /// Insert an object to a folder below
+ void insertToFolderAfter();
+
private slots:
/// SLOT, that is called after the operation is started. Update workshop state according to
/// the started operation, e.g. visualizes the property panel and connect to it.
<file>pictures/eyeopen.png</file>
<file>pictures/transparency.png</file>
+ <file>pictures/features_folder.png</file>
</qresource>
</RCC>