#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultField.h>
-#include "ModelAPI_Folder.h"
+#include <ModelAPI_Folder.h>
+#include <ModelAPI_AttributeReference.h>
#include <Config_DataModelReader.h>
XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
: QObject(theParent),
myWorkshop(theParent),
- mySeparator1(0), mySeparator2(0)
+ mySeparator1(0), mySeparator2(0), mySeparator3(0)
{
}
mySeparator2 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
mySeparator2->setSeparator(true);
+ mySeparator3 = ModuleBase_Tools::createAction(QIcon(), "", aDesktop);
+ mySeparator3->setSeparator(true);
+
//mySelectActions = new QActionGroup(this);
//mySelectActions->setExclusive(true);
tr("Move into the next folder"), aDesktop);
addAction("ADD_TO_FOLDER_AFTER_CMD", aAction);
+ aAction = ModuleBase_Tools::createAction(QIcon(),
+ tr("Move out before the folder"), aDesktop);
+ addAction("ADD_OUT_FOLDER_BEFORE_CMD", aAction);
+
+ aAction = ModuleBase_Tools::createAction(QIcon(),
+ tr("Move out after the folder"), aDesktop);
+ addAction("ADD_OUT_FOLDER_AFTER_CMD", aAction);
+
buildObjBrowserMenu();
buildViewerMenu();
}
QModelIndex aLastIdx = aIndexes.last();
QModelIndex aParentIdx = aFirstIdx.parent();
- if (aParentIdx == aLastIdx.parent()) {
- // if all selected are from the same level
+ // if all selected are from the same level
+ bool isSameParent = true;
+ foreach(QModelIndex aIdx, aIndexes) {
+ if (aIdx.parent() != aParentIdx) {
+ isSameParent = false;
+ break;
+ }
+ }
+ if (isSameParent) {
+ // Check is selection continuous
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);
+ DocumentPtr aDoc = aMgr->activeDocument();
+ std::list<FeaturePtr> aFeatures = aSelMgr->getSelectedFeatures();
+
+ bool isContinuos = true;
+ if (aSelected > 1) {
+ int aId = -1;
+ foreach(FeaturePtr aF, aFeatures) {
+ if (aId == -1)
+ aId = aDoc->index(aF);
+ else {
+ aId++;
+ if (aId != aDoc->index(aF)) {
+ isContinuos = false;
+ break;
+ }
+ }
+ }
}
+ if (isContinuos) {
+ ObjectPtr aDataObj = aModel->object(aParentIdx);
- ObjectPtr aNextObj;
- if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
- QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
- aNextObj = aModel->object(aNextIdx);
- }
+ ObjectPtr aPrevObj;
+ if (aFirstIdx.row() > 0) {
+ QModelIndex aPrevIdx = aFirstIdx.sibling(aFirstIdx.row() - 1, 0);
+ aPrevObj = aModel->object(aPrevIdx);
+ }
- 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);
+ ObjectPtr aNextObj;
+ if (aLastIdx.row() < (aModel->rowCount(aParentIdx) - 1)) {
+ QModelIndex aNextIdx = aFirstIdx.sibling(aLastIdx.row() + 1, 0);
+ aNextObj = aModel->object(aNextIdx);
+ }
- action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
- action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
- action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
+ 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 = !isInFolder;
+
+ bool hasFirst = false;
+ bool hasLast = false;
+ if (isInFolder) {
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aDataObj);
+ FeaturePtr aFirstFeatureInFolder;
+ AttributeReferencePtr aFirstFeatAttr =
+ aFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+ if (aFirstFeatAttr)
+ aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
+ hasFirst = (aFirstFeatureInFolder == aFeatures.front());
+
+ FeaturePtr aLastFeatureInFolder;
+ AttributeReferencePtr aLastFeatAttr =
+ aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+ if (aLastFeatAttr)
+ aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+ hasLast = (aLastFeatureInFolder == aFeatures.back());
+ }
+ action("INSERT_FOLDER_CMD")->setEnabled(isOutsideFolder);
+ action("ADD_TO_FOLDER_BEFORE_CMD")->setEnabled(isOutsideFolder && isPrevFolder);
+ action("ADD_TO_FOLDER_AFTER_CMD")->setEnabled(isOutsideFolder && isNextFolder);
+ action("ADD_OUT_FOLDER_BEFORE_CMD")->setEnabled(isInFolder && hasFirst);
+ action("ADD_OUT_FOLDER_AFTER_CMD")->setEnabled(isInFolder && hasLast);
+ }
}
} // end folder management commands
aList.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
aList.append(action("ADD_TO_FOLDER_AFTER_CMD"));
aList.append(mySeparator2);
+ aList.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
+ aList.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
+ aList.append(mySeparator3);
aList.append(action("CLEAN_HISTORY_CMD"));
aList.append(action("DELETE_CMD"));
myObjBrowserMenus[ModelAPI_Feature::group()] = aList;
aActions.append(action("HIDE_CMD"));
aActions.append(action("SHOW_ONLY_CMD"));
aActions.append(mySeparator2);
+ aActions.append(action("ADD_TO_FOLDER_BEFORE_CMD"));
+ aActions.append(action("ADD_TO_FOLDER_AFTER_CMD"));
+ aActions.append(action("ADD_OUT_FOLDER_BEFORE_CMD"));
+ aActions.append(action("ADD_OUT_FOLDER_AFTER_CMD"));
+ aActions.append(mySeparator3);
//aActions.append(action("MOVE_CMD"));
aActions.append(action("COLOR_CMD"));
aActions.append(action("DEFLECTION_CMD"));
QAction* mySeparator1;
QAction* mySeparator2;
+ QAction* mySeparator3;
};
#endif
#include <ModelAPI_ResultField.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_Folder.h>
+#include <ModelAPI_AttributeReference.h>
#include <Config_FeatureMessage.h>
#include <Config_DataModelReader.h>
/// Returns pointer on document if the given object is document object
ModelAPI_Document* getSubDocument(void* theObj)
{
- ModelAPI_Document* aDoc = dynamic_cast<ModelAPI_Document*>((ModelAPI_Entity*)theObj);
+ ModelAPI_Document* aDoc = 0;
+ try {
+ aDoc = dynamic_cast<ModelAPI_Document*>((ModelAPI_Entity*)theObj);
+ } catch(...) {}
return aDoc;
}
std::set<ObjectPtr> aObjects = aUpdMsg->objects();
std::set<ObjectPtr>::const_iterator aIt;
- std::string aObjType;
for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
ObjectPtr aObject = (*aIt);
if (aObject->data()->isValid()) {
QModelIndex aIndex = objectIndex(aResult, 0);
removeRows(0, aResult->stepsSize(), aIndex);
} else {
- QModelIndex aIndex = objectIndex(aObject, 0);
- if (aIndex.isValid()) {
- emit dataChanged(aIndex, aIndex);
+ if (aObject->groupName() == ModelAPI_Folder::group()) {
+ rebuildDataTree();
+ } else {
+ QModelIndex aIndex = objectIndex(aObject, 0);
+ if (aIndex.isValid()) {
+ emit dataChanged(aIndex, aIndex);
+ }
}
}
} else {
}
}
}
+ int aFRow = -1;
+ FolderPtr aFolder = aDoc->findContainingFolder(aFeature, aFRow);
+ if (aFolder.get())
+ aRow = aFRow;
} else {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult.get()) {
ModelAPI_ResultField* aFieldRes = dynamic_cast<ModelAPI_ResultField*>(aObj);
if (aFieldRes)
return aFieldRes->stepsSize();
+ ModelAPI_Folder* aFolder = dynamic_cast<ModelAPI_Folder*>(aObj);
+ if (aFolder)
+ return getNumberOfFolderItems(aFolder);
}
}
}
dynamic_cast<ModelAPI_ResultField*>(aParentObj);
if (aFieldRes) {
aIndex = createIndex(theRow, theColumn, aFieldRes->step(theRow));
+ } else {
+ ModelAPI_Folder* aFolder = dynamic_cast<ModelAPI_Folder*>(aParentObj);
+ ObjectPtr aObj = getObjectInFolder(aFolder, theRow);
+ if (aObj.get())
+ aIndex = objectIndex(aObj, theColumn);
}
}
}
}
ObjectPtr aObj = object(theIndex);
if (!aObj.get()) {
- // It can b e a step of a field
+ // It can be a step of a field
ModelAPI_ResultField::ModelAPI_FieldStep* aStep =
dynamic_cast<ModelAPI_ResultField::ModelAPI_FieldStep*>
((ModelAPI_Entity*)theIndex.internalPointer());
if (aCompFea.get()) {
return objectIndex(aCompFea);
}
+ DocumentPtr aDoc = aFeature->document();
+ int aRow;
+ FolderPtr aFolder = aDoc->findContainingFolder(aFeature, aRow);
+ if (aFolder.get())
+ return objectIndex(aFolder);
}
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
if (aResult.get()) {
}
return NoneState;
}
+
+
+int XGUI_DataModel::getNumberOfFolderItems(const ModelAPI_Folder* theFolder) const
+{
+ DocumentPtr aDoc = theFolder->document();
+
+ FeaturePtr aFirstFeatureInFolder;
+ AttributeReferencePtr aFirstFeatAttr =
+ theFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+ if (aFirstFeatAttr)
+ aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
+ if (!aFirstFeatureInFolder.get())
+ return 0;
+
+ FeaturePtr aLastFeatureInFolder;
+ AttributeReferencePtr aLastFeatAttr =
+ theFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
+ if (aLastFeatAttr)
+ aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+ if (!aLastFeatureInFolder.get())
+ return 0;
+
+ int aFirst = aDoc->index(aFirstFeatureInFolder);
+ int aLast = aDoc->index(aLastFeatureInFolder);
+ return aLast - aFirst + 1;
+}
+
+ObjectPtr XGUI_DataModel::getObjectInFolder(const ModelAPI_Folder* theFolder, int theId) const
+{
+ DocumentPtr aDoc = theFolder->document();
+
+ FeaturePtr aFirstFeatureInFolder;
+ AttributeReferencePtr aFirstFeatAttr =
+ theFolder->data()->reference(ModelAPI_Folder::FIRST_FEATURE_ID());
+ if (aFirstFeatAttr)
+ aFirstFeatureInFolder = ModelAPI_Feature::feature(aFirstFeatAttr->value());
+ if (!aFirstFeatureInFolder.get())
+ return ObjectPtr();
+
+ int aFirst = aDoc->index(aFirstFeatureInFolder);
+ return aDoc->object(ModelAPI_Feature::group(), aFirst + theId);
+}
/// \param fromRoot - root document flag
QStringList listOfShowNotEmptyFolders(bool fromRoot = true) const;
+ int getNumberOfFolderItems(const ModelAPI_Folder* theFolder) const;
+ ObjectPtr getObjectInFolder(const ModelAPI_Folder* theFolder, int theId) const;
+
VisibilityState getVisibilityState(const QModelIndex& theIndex) const;
void addShownFolder(DocumentPtr theDoc, QString theFolder)
}
}
}
+
+std::list<FeaturePtr> XGUI_SelectionMgr::getSelectedFeatures()
+{
+ std::list<FeaturePtr> aFeatures;
+ QObjectPtrList aObjects = selection()->selectedObjects();
+ if (aObjects.isEmpty())
+ return aFeatures;
+
+ foreach(ObjectPtr aObj, aObjects) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature.get())
+ aFeatures.push_back(aFeature);
+ }
+ return aFeatures;
+}
\ No newline at end of file
#include "XGUI.h"
#include <ModuleBase_Definitions.h>
#include <ModuleBase_ISelection.h>
+#include <ModelAPI_Feature.h>
#include <QObject>
#include <QModelIndexList>
/// \param thePlace a widget where selection has happened.
void updateSelectionBy(const ModuleBase_ISelection::SelectionPlace& thePlace);
+ /// Returns list of selected features (ignores other selected objects)
+ std::list<FeaturePtr> getSelectedFeatures();
+
signals:
//! Emited when selection in a one of viewers was changed
void selectionChanged();
insertToFolder(true);
} else if (theId == "ADD_TO_FOLDER_AFTER_CMD") {
insertToFolder(false);
+ } else if (theId == "ADD_OUT_FOLDER_BEFORE_CMD") {
+ moveOutFolder(true);
+ } else if (theId == "ADD_OUT_FOLDER_AFTER_CMD") {
+ moveOutFolder(false);
} else if (theId == "SELECT_RESULT_CMD") {
//setViewerSelectionMode(-1);
//IMP: an attempt to use result selection with other selection modes
void XGUI_Workshop::insertToFolder(bool isBefore)
{
- QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
- if (aObjects.isEmpty())
- return;
-
- std::list<FeaturePtr> aFeatures;
- foreach(ObjectPtr aObj, aObjects) {
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
- if (aFeature.get())
- aFeatures.push_back(aFeature);
- }
+ std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
if (aFeatures.empty())
return;
aDoc->moveToFolder(aFeatures, aFolder);
aMgr->finishOperation();
}
+
+void XGUI_Workshop::moveOutFolder(bool isBefore)
+{
+ std::list<FeaturePtr> aFeatures = mySelector->getSelectedFeatures();
+ if (aFeatures.empty())
+ return;
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->activeDocument();
+
+ aMgr->startOperation();
+ aDoc->removeFromFolder(aFeatures, isBefore);
+ aMgr->finishOperation();
+}
\ No newline at end of file
/// Insert an object to a folder above or below
void insertToFolder(bool isBefore);
+ /// Insert an object to a folder above or below
+ void moveOutFolder(bool isBefore);
+
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.