ADD_CUSTOM_TARGET(INSTALL_DOCS
COMMAND "${DOXYGEN_EXECUTABLE}"
- COMMAND "${CMAKE_COMMAND}" --build "${PROJECT_BINARY_DIR}" --target install
+ COMMAND "${CMAKE_COMMAND}" --build "${PROJECT_BINARY_DIR}" --target install --config ${CMAKE_BUILD_TYPE}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/doc"
)
INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tui DESTINATION doc OPTIONAL)
import salome
from salome.geom import geomBuilder
+def getObjectIndex(theName):
+ aStudy = salome.myStudy
+ aId = 0
+ aObj = aStudy.FindObjectByName(theName, "GEOM")
+ while len(aObj) != 0:
+ aId = aId + 1
+ aName = theName + '_' + str(aId)
+ aObj = aStudy.FindObjectByName(aName, "GEOM")
+ return aId
## @ingroup Plugins
# Feature to export all shapes and groups into the GEOM module
## Exports all bodies
def exportBodies(self):
+ global ShapeIndex
kResultBodyType = "Bodies"
aPartSize = self.Part.size(kResultBodyType)
if aPartSize == 0:
aDump = aShape.getShapeStream()
# Load shape to SALOME Geom
aBrep = self.geompy.RestoreShape(aDump)
- self.geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx + 1))
+ aName = aBodyResult.data().name()
+
+ # Make unique name
+ aId = getObjectIndex(aName)
+ if aId != 0:
+ aName = aName + '_' + str(aId)
+
+ self.geompy.addToStudy(aBrep, aName)
self.geomObjects.append([aShape, aBrep])
## Exports all groups
if (!aDimAIS.IsNull()) {
aDimAIS->DimensionAspect()->SetCommonColor(aColor);
}
+ Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
+ aContext->SetColor(anAIS, aColor, false);
}
void GeomAPI_AISObject::setWidth(const double& theWidth)
if (!aDimAIS.IsNull()) {
aDimAIS->DimensionAspect()->SetCommonColor(aColor);
}
+ Handle(AIS_InteractiveContext) aContext = anAIS->GetContext();
+ aContext->SetColor(anAIS, aColor, false);
}
bool GeomAPI_AISObject::empty() const
return;
}
}
+ //BRepTools::Write(aNewShape, "Selection0.brep");
aSel.Select(aNewShape, aContext);
}
TopoDS_Shape aSubShape = aSubSh->impl<TopoDS_Shape>();
TopoDS_Shape aContext = aCont->shape()->impl<TopoDS_Shape>();
#ifdef DEB_NAMING
+ if(aSubShape.ShapeType() == TopAbs_COMPOUND) {
BRepTools::Write(aSubShape, "Selection.brep");
BRepTools::Write(aContext, "Context.brep");
+ }
#endif
std::shared_ptr<Model_Document> aDoc =
std::dynamic_pointer_cast<Model_Document>(aCont->document());
case TopAbs_EDGE:
{
// name structure: F1 | F2 [| F3 | F4], where F1 & F2 the faces which gives the Edge in trivial case
- // if it is not atrivial case we use localization by neighbours. F3 & F4 - neighbour faces
+ // if it is not atrivial case we use localization by neighbours. F3 & F4 - neighbour faces
+ if (BRep_Tool::Degenerated(TopoDS::Edge(aSubShape))) {
+ aName = "Degenerated_Edge";
+ break;
+ }
TopTools_IndexedDataMapOfShapeListOfShape aMap;
TopExp::MapShapesAndAncestors(aContext, TopAbs_EDGE, TopAbs_FACE, aMap);
TopTools_IndexedMapOfShape aSMap; // map for ancestors of the sub-shape
//n = aList.Extent();
#endif
int n = aList.Extent();
- if(n < 3) { // open topology case => via edges
+ if(n < 3) { // open topology case or Compound case => via edges
TopTools_IndexedDataMapOfShapeListOfShape aMap;
TopExp::MapShapesAndAncestors(aContext, TopAbs_VERTEX, TopAbs_EDGE, aMap);
- const TopTools_ListOfShape& aList2 = aMap.FindFromKey(aSubShape);
- if(aList2.Extent() >= 2) { // regular solution
- TopTools_ListIteratorOfListOfShape itl(aList2);
+ const TopTools_ListOfShape& aList22 = aMap.FindFromKey(aSubShape);
+ if(aList22.Extent() >= 2) { // regular solution
+#ifdef FIX_BUG1
+
+ // bug! duplication; fix is below
+ aFMap.Clear();
+ TopTools_ListOfShape aListE;
+ TopTools_ListIteratorOfListOfShape itl2(aList22);
+ for (int i = 1;itl2.More();itl2.Next(),i++) {
+ if(aFMap.Add(itl2.Value()))
+ aListE.Append(itl2.Value());
+ }
+ n = aListE.Extent();
+#endif
+ TopTools_ListIteratorOfListOfShape itl(aListE);
for (int i = 1;itl.More();itl.Next(),i++) {
const TopoDS_Shape& anEdge = itl.Value();
std::string anEdgeName = GetShapeName(aDoc, anEdge, selectionLabel());
else
aName += "|" + anEdgeName;
}
+ }//reg
+ else { // dangle vertex: if(aList22.Extent() == 1)
+ //it should be already in DF
}
}
else {
// DEB
//#include <TCollection_AsciiString.hxx>
//#include <TDF_Tool.hxx>
-#define DEB_IMPORT 1
+//#define DEB_IMPORT 1
Model_ResultBody::Model_ResultBody()
{
Model_Application::getApplication()->deleteAllDocuments();
}
-void Model_Session::startOperation()
+void Model_Session::startOperation(const std::string& theId)
{
ROOT_DOC->startOperation();
static std::shared_ptr<Events_Message> aStartedMsg
setCheckTransactions(true);
}
+//! Returns stack of performed operations
+std::list<std::string> Model_Session::undoList()
+{
+ std::list<std::string> temp;
+ temp.push_front("Part");
+ temp.push_front("Sketch");
+ temp.push_front("Extrusion");
+ return temp;
+}
+//! Returns stack of rolled back operations
+std::list<std::string> Model_Session::redoList()
+{
+ std::list<std::string> temp;
+ return temp;
+}
+
FeaturePtr Model_Session::createFeature(string theFeatureID)
{
if (this != myImpl) {
MODEL_EXPORT virtual void closeAll();
//! Starts a new operation (opens a tansaction)
- MODEL_EXPORT virtual void startOperation();
+ MODEL_EXPORT virtual void startOperation(const std::string& theId);
//! Finishes the previously started operation (closes the transaction)
MODEL_EXPORT virtual void finishOperation();
//! Aborts the operation
MODEL_EXPORT virtual bool canRedo();
//! Redoes last operation
MODEL_EXPORT virtual void redo();
+ //! Returns stack of performed operations
+ MODEL_EXPORT virtual std::list<std::string> undoList();
+ //! Returns stack of rolled back operations
+ MODEL_EXPORT virtual std::list<std::string> redoList();
/// Returns the root document of the application (that may contains sub-documents)
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
virtual void closeAll() = 0;
//! Starts a new operation (opens a tansaction)
- virtual void startOperation() = 0;
+ //! \param theId of operation for history (optional)
+ virtual void startOperation(const std::string& theId) = 0;
//! Finishes the previously started operation (closes the transaction)
virtual void finishOperation() = 0;
//! Aborts the operation
virtual bool canRedo() = 0;
//! Redoes last operation
virtual void redo() = 0;
+ //! Returns stack of performed operations (from last to first)
+ virtual std::list<std::string> undoList() = 0;
+ //! Returns stack of rolled back operations (from last rolled back to first)
+ virtual std::list<std::string> redoList() = 0;
/// Registers the plugin that creates features.
/// It is obligatory for each plugin to call this function on loading to be found by
ModuleBase_WidgetLabel.h
ModuleBase_IPrefMgr.h
ModuleBase_Preferences.h
+ ModuleBase_ActionInfo.h
)
SET(PROJECT_SOURCES
ModuleBase_ResultPrs.cpp
ModuleBase_WidgetLabel.cpp
ModuleBase_Preferences.cpp
+ ModuleBase_ActionInfo.cpp
)
SET(PROJECT_LIBRARIES
Config
+ Events
ModelAPI
GeomAPI
GeomAlgoAPI
--- /dev/null
+/*
+ * ModuleBase_ActionInfo.cpp
+ *
+ * Created on: Feb 4, 2015
+ * Author: sbh
+ */
+
+#include <ModuleBase_ActionInfo.h>
+
+ModuleBase_ActionInfo::ModuleBase_ActionInfo()
+{
+ initDefault();
+}
+
+ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
+{
+ initDefault();
+}
+
+ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
+{
+ initDefault();
+ icon = theIcon;
+ text = theText;
+}
+
+ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
+{
+}
+
+void ModuleBase_ActionInfo::initFrom(QAction* theAction)
+{
+ // By convenience, QAction for a feature keeps feature's id as data (QVariant);
+ if (theAction->data().isValid()) {
+ id = theAction->data().toString();
+ }
+ checkable = theAction->isCheckable();
+ checked = theAction->isChecked();
+ enabled = theAction->isEnabled();
+ visible = theAction->isVisible();
+ icon = theAction->icon();
+ text = theAction->text();
+ iconText = theAction->iconText();
+ toolTip = theAction->toolTip();
+ // statusTip = theAction->statusTip();
+ // whatsThis = theAction->whatsThis();
+ shortcut = theAction->shortcut();
+ font = theAction->font();
+}
+
+void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
+{
+ id = QString::fromStdString(theMessage->id());
+ iconFile = QString::fromStdString(theMessage->icon());
+ if (!iconFile.isEmpty()) {
+ icon = QIcon(iconFile);
+ }
+ text = QString::fromStdString(theMessage->text());
+ toolTip = QString::fromStdString(theMessage->tooltip());
+ QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
+ if (!aShortcutStr.isEmpty()) {
+ shortcut = QKeySequence(aShortcutStr);
+ }
+ // If feature requires PropertyPannel for input, it should be checkable
+ checkable = theMessage->isUseInput();
+}
+
+QAction* ModuleBase_ActionInfo::makeAction(QObject* theParent)
+{
+ QAction* aResult = new QAction(icon, text, theParent);
+ aResult->setCheckable(checkable);
+ aResult->setChecked(checked);
+ aResult->setEnabled(enabled);
+ aResult->setVisible(visible);
+ aResult->setIconText(iconText);
+ aResult->setToolTip(toolTip);
+ // aResult->setStatusTip(statusTip);
+ // aResult->setWhatsThis(whatsThis);
+ aResult->setShortcut(shortcut);
+ aResult->setFont(font);
+ // By convenience, QAction for a feature keeps feature's id as data (QVariant);
+ aResult->setData(id);
+ return aResult;
+}
+
+void ModuleBase_ActionInfo::initDefault()
+{
+ id = QString();
+ checkable = false;
+ checked = false;
+ enabled = true;
+ visible = true;
+ icon = QIcon();
+ text = QString();
+ iconText = QString();
+ iconFile = QString();
+ toolTip = QString();
+ // statusTip = QString();
+ // whatsThis = QString();
+ shortcut = QKeySequence();
+ font = QFont();
+}
--- /dev/null
+/*
+ * ActionInfo.h
+ *
+ * Created on: Feb 4, 2015
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_ACTIONINFO_H_
+#define MODULEBASE_ACTIONINFO_H_
+
+#include <ModuleBase.h>
+#include <Config_FeatureMessage.h>
+
+#include <QAction>
+#include <QIcon>
+#include <QKeySequence>
+#include <QFont>
+
+#include <memory>
+
+/*!
+ * Structure to pass info about QActions, AppElements_Commands, etc.
+ */
+struct MODULEBASE_EXPORT ModuleBase_ActionInfo
+{
+ QString id;
+
+ bool checkable; //!< action's checkable state
+ bool checked; //!< action's checked state
+ bool enabled; //!< action's enabled state
+ bool visible; //!< action's visibility state
+ QIcon icon; //!< action's icon
+ QString text; //!< action's text
+ QString iconText; //!< action's descriptive icon text
+ QString iconFile; //!< path to icon's file. Can not be initialized from QAction
+ QString toolTip; //!< action's tooltip
+ // QString statusTip;
+ // QString whatsThis;
+ QKeySequence shortcut; //!< action's primary shortcut key
+ QFont font; //!< action's text font
+
+ public:
+ //! Default constructor, \sa initDefault
+ ModuleBase_ActionInfo();
+ //! Initializes structure with default values, except text
+ ModuleBase_ActionInfo(const QString &text);
+ //! Initializes structure with default values, except icon and text
+ ModuleBase_ActionInfo(const QIcon &icon, const QString &text);
+ virtual ~ModuleBase_ActionInfo();
+
+ //! Fills itself with info from given \param theAction
+ void initFrom(QAction* theAction);
+ //! Fills itself with info from given \param theFeatureMessage
+ void initFrom(std::shared_ptr<Config_FeatureMessage> theFeatureMessage);
+ //! Creates new QAction with given parent and data initialized from this structure
+ //! \param theParent - parent of created action
+ QAction* makeAction(QObject* theParent = 0);
+
+ protected:
+ //! Initializes structure with default values, like QAction()
+ void initDefault();
+};
+
+typedef ModuleBase_ActionInfo ActionInfo;
+
+#endif /* XGUI_ACTIONINFO_H_ */
/// Update current viewer
virtual void update() = 0;
+ /// Method returns True if the viewer can process editing objects
+ /// by mouse drugging. If this is impossible thet it has to return False.
+ virtual bool canDragByMouse() const { return true; }
+
signals:
/// Signal emited when last view window is closed
void lastViewClosed();
void ModuleBase_Operation::start()
{
- ModelAPI_Session::get()->startOperation();
+ QString anId = getDescription()->operationId();
+ ModelAPI_Session::get()->startOperation(anId.toStdString());
if (!myIsEditing)
createFeature();
return aAction;
}
+QAction* NewGeom_Module::addFeature(const QString& theWBName, const ActionInfo& theInfo)
+{
+ return addFeature(theWBName,
+ theInfo.id,
+ theInfo.text,
+ theInfo.toolTip,
+ theInfo.icon,
+ theInfo.shortcut);
+}
+
+
//******************************************************
QAction* NewGeom_Module::addDesktopCommand(const QString& theId, const QString& theTitle,
const QString& theTip, const QIcon& theIcon,
#include <LightApp_Module.h>
#include <XGUI_SalomeConnector.h>
+#include <ModuleBase_ActionInfo.h>
+
#include <QStringList>
#include <QMap>
const QKeySequence& theKeys = QKeySequence(),
bool isCheckable = false);
+ virtual QAction* addFeature(const QString& theWBName,
+ const ActionInfo& theInfo);
+
+
virtual QAction* addDesktopCommand(const QString& theId, const QString& theTitle,
const QString& theTip, const QIcon& theIcon,
const QKeySequence& theKeys, bool isCheckable,
{
OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
Handle(AIS_InteractiveContext) aContext = AISContext();
- if (aContext->HasDetected())
+ if (aContext->HasDetected()) // Set focus to provide key events in the view
aViewWnd->getViewPort()->setFocus(Qt::MouseFocusReason);
emit mouseMove(myView, theEvent);
}
+//**********************************************
+bool NewGeom_SalomeViewer::canDragByMouse() const
+{
+ OCCViewer_Viewer* aViewer = mySelector->viewer();
+ SUIT_ViewWindow* aWnd = aViewer->getViewManager()->getActiveView();
+ OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(aWnd);
+ if (aViewWnd) {
+ return (aViewWnd->interactionStyle() == 0);
+ }
+ return true;
+}
+
+
//**********************************************
void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
{
/// Update current viewer
virtual void update();
+ /// Method returns True if the viewer can process editing objects
+ /// by mouse drugging. If this is impossible thet it has to return False.
+ virtual bool canDragByMouse() const;
private slots:
void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
}
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation();
+ aMgr->startOperation("DeletePartSet");
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
for (; anIt != aLast; anIt++) {
if (!(theEvent->buttons() & Qt::LeftButton))
return;
+ // Clear dragging mode
+ myIsDragging = false;
+
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+ ModuleBase_IViewer* aViewer = aWorkshop->viewer();
+ if (!aViewer->canDragByMouse())
+ return;
+
ModuleBase_Operation* aOperation = aWorkshop->currentOperation();
if (aOperation && aOperation->isEditOperation()) {
ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
}
}
- // Clear dragging mode
- myIsDragging = false;
-
// Use only for sketch operations
if (aOperation && myCurrentSketch) {
if (!PartSet_Tools::sketchPlane(myCurrentSketch))
return;
// MoveTo in order to highlight current object
- ModuleBase_IViewer* aViewer = aWorkshop->viewer();
aViewer->AISContext()->MoveTo(theEvent->x(), theEvent->y(), theWnd->v3dView());
// Remember highlighted objects for editing
void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+ ModuleBase_IViewer* aViewer = aWorkshop->viewer();
+ if (!aViewer->canDragByMouse())
+ return;
ModuleBase_Operation* aOp = aWorkshop->currentOperation();
if (aOp) {
if (sketchOperationIdList().contains(aOp->id())) {
get2dPoint(theWnd, theEvent, myClickedPoint);
// Only for sketcher operations
- ModuleBase_IViewer* aViewer = aWorkshop->viewer();
if (myIsDragging) {
if (myDragDone) {
//aOp->commit();
|| theKind == SketchPlugin_ConstraintRigid::ID();
}
-ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape,
+ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape,
const ObjectPtr& theObject,
CompositeFeaturePtr theSketch)
{
/// \param theObject a selected result object
/// \param theSketch a sketch feature
/// \return result of created feature
- static ResultPtr createFixedObjectByEdge(const TopoDS_Shape& theShape,
- const ObjectPtr& theObject,
- CompositeFeaturePtr theSketch);
+ static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape,
+ const ObjectPtr& theObject,
+ CompositeFeaturePtr theSketch);
/// Checks whether the list of selected presentations contains the given one
/// \param theSelected a list of presentations
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Pnt2d.h>
+#include <SketchPlugin_Feature.h>
+
#include <QGroupBox>
#include <QGridLayout>
#include <QLabel>
void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ Handle(V3d_View) aView = theWnd->v3dView();
// TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
- //NCollection_List<TopoDS_Shape> aShapes;
- //std::list<ObjectPtr> aObjects;
- //aSelection->selectedShapes(aShapes, aObjects);
- //if (aShapes.Extent() > 0) {
- // TopoDS_Shape aShape = aShapes.First();
- // double aX, aY;
- // if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
- // setPoint(aX, aY);
-
- // PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
- // emit vertexSelected(aObjects.front(), aShape);
- // emit focusOutWidget(this);
- // return;
- // }
- //}
+ NCollection_List<TopoDS_Shape> aShapes;
+ std::list<ObjectPtr> aObjects;
+ aSelection->selectedShapes(aShapes, aObjects);
+ // if we have selection
+ if (aShapes.Extent() > 0) {
+ TopoDS_Shape aShape = aShapes.First();
+ ObjectPtr aObject = aObjects.front();
+ FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
+ if (aSelectedFeature.get() != NULL) {
+ std::shared_ptr<SketchPlugin_Feature> aSPFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+ if ((!aSPFeature) && (!aShape.IsNull()))
+ PartSet_Tools::createFixedObjectByExternal(aShape, aObject, mySketch);
+ }
+ double aX, aY;
+ if (getPoint2d(aView, aShape, aX, aY)) {
+ setPoint(aX, aY);
+
+ PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+ emit vertexSelected();
+ emit focusOutWidget(this);
+ return;
+ }
+ }
// End of Bug dependent fragment
// A case when point is taken from mouse event
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
double aX, anY;
- Handle(V3d_View) aView = theWnd->v3dView();
PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
if (!setPoint(aX, anY))
return;
- std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
- QList<FeaturePtr> aIgnore;
- aIgnore.append(feature());
-
- double aTolerance = aView->Convert(7);
- std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
- PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
- if (aAttrPnt.get() != NULL) {
- aFeaturePoint->setValue(aAttrPnt->pnt());
- PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
- emit vertexSelected();
- }
+ /// Start alternative code
+ //std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
+ // GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
+ //QList<FeaturePtr> aIgnore;
+ //aIgnore.append(feature());
+
+ //double aTolerance = aView->Convert(7);
+ //std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
+ // PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
+ //if (aAttrPnt.get() != NULL) {
+ // aFeaturePoint->setValue(aAttrPnt->pnt());
+ // PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
+ // emit vertexSelected();
+ //}
+ /// End alternative code
emit focusOutWidget(this);
}
std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
if ((!aSPFeature) && (!myShape->isNull())) {
// Processing of external (non-sketch) object
- ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl<TopoDS_Shape>(),
- mySelectedObject, mySketch);
+ ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
+ mySelectedObject, mySketch);
if (aObj) {
PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
that->mySelectedObject = aObj;
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if ((!aSPFeature) && (!myShape->isNull())) {
- ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl<TopoDS_Shape>(),
- mySelectedObject, mySketch);
+ ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(myShape->impl<TopoDS_Shape>(),
+ mySelectedObject, mySketch);
if (aObj) {
PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
that->mySelectedObject = aObj;
if (!aConst)
return thePrevious;
+
+ std::shared_ptr<SketchPlugin_Feature> aSketchFea =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(ModelAPI_Feature::feature(aConst));
+ if (aSketchFea.get() != NULL) {
+ if (aSketchFea->isExternal())
+ return thePrevious;
+ }
aShape = aConst->shape();
}
else {
{
AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
if (aAttr)
- return aAttr->context().get() == NULL;
+ return aAttr->context().get() != NULL;
return false;
}
/// Customize presentation of the feature
virtual void customisePresentation(AISObjectPtr thePrs)
{
- // if this is an edge
- if (thePrs->getShapeType() == 6)
+ // if this is an edge or vertex
+ if ((thePrs->getShapeType() == 6) || (thePrs->getShapeType() == 7)) {
thePrs->setWidth(3);
+ if (isExternal())
+ thePrs->setColor(0,255,0);
+ }
// if this is a vertex
//else if (thePrs->getShapeType() == 7)
// thePrs->setPointMarker(6, 2.);
XGUI_Tools.h
XGUI_ViewerProxy.h
XGUI_Workshop.h
+ XGUI_HistoryMenu.h
)
SET(PROJECT_AUTOMOC
XGUI_Tools.cpp
XGUI_ViewerProxy.cpp
XGUI_Workshop.cpp
+ XGUI_HistoryMenu.cpp
)
SET(PROJECT_RESOURCES
}
}
-QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
+QKeySequence XGUI_ActionsMgr::registerShortcut(const QKeySequence& theKeySequence)
{
if (theKeySequence.isEmpty()) {
return QKeySequence();
}
- QKeySequence aResult(theKeySequence);
- if (myShortcuts.contains(aResult)) {
- QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence);
+ if (myShortcuts.contains(theKeySequence)) {
+ QString aMessage = tr("Shortcut %1 is already defined. Ignore.");
+ aMessage = aMessage.arg(theKeySequence.toString());
Events_Error::send(aMessage.toStdString());
return QKeySequence();
}
- myShortcuts.append(aResult);
+ myShortcuts.append(theKeySequence);
+ return theKeySequence;
+}
+
+QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
+{
+ if (theKeySequence.isEmpty()) {
+ return QKeySequence();
+ }
+ QKeySequence aResult(theKeySequence);
+ registerShortcut(aResult);
return aResult;
}
/// Registers shortcut (key sequence) for the command triggering
/// \param theKeySequence a key sequence to register
+ QKeySequence registerShortcut(const QKeySequence& theKeySequence);
+
+ /// This is an overloaded function.
+ /// Registers shortcut (key sequence) for the command triggering
+ /// \param theKeySequence - string that contain a key sequence to register
QKeySequence registerShortcut(const QString& theKeySequence);
//! Redefinition of Events_Listener method
void connectViewer() const;
/// Add menu atems for viewer into the given menu (used in SALOME mode)
- /// \param a popup menu to be shown in the viewer
+ /// \param theMenu a popup menu to be shown in the viewer
void addViewerItems(QMenu* theMenu) const;
signals:
--- /dev/null
+/*
+ * XGUI_HistoryMenu.cpp
+ *
+ * Created on: Feb 2, 2015
+ * Author: sbh
+ */
+
+#include <XGUI_HistoryMenu.h>
+
+#include <ModelAPI_Session.h>
+
+#include <QListWidget>
+#include <QWidgetAction>
+#include <QToolButton>
+#include <QAction>
+
+//! Extends given feature with previously created context menu.
+//! \param theId - Id of the feature to add \a theMenu
+//! \param theMenu - Enables or disables menu feature
+XGUI_HistoryMenu::XGUI_HistoryMenu(QAction* theParent)
+ : QMenu(NULL),
+ myHistoryList(NULL)
+{
+ theParent->setMenu(this);
+ initMenu();
+
+ connect(theParent, SIGNAL(destroyed()), this, SLOT(deleteLater()));
+}
+
+//! Extends given feature with previously created context menu.
+//! \param theId - Id of the feature to add \a theMenu
+//! \param theMenu - Enables or disables menu feature
+XGUI_HistoryMenu::XGUI_HistoryMenu(QToolButton* theParent)
+ : QMenu(theParent),
+ myHistoryList(NULL)
+{
+ theParent->setMenu(this);
+ theParent->setPopupMode(QToolButton::MenuButtonPopup);
+
+ initMenu();
+}
+
+void XGUI_HistoryMenu::initMenu()
+{
+ myHistoryList = new QListWidget(this);
+ QWidgetAction* aListAction = new QWidgetAction(this);
+ aListAction->setDefaultWidget(myHistoryList);
+ this->addAction(aListAction);
+ myHistoryList->setMouseTracking(true); // track mouse hover
+ myHistoryList->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ connect(myHistoryList, SIGNAL(itemEntered(QListWidgetItem *)), this,
+ SLOT(setStackSelectedTo(QListWidgetItem *)));
+ connect(myHistoryList, SIGNAL(itemClicked(QListWidgetItem *)), this,
+ SLOT(onItemPressed(QListWidgetItem *)));
+}
+
+XGUI_HistoryMenu::~XGUI_HistoryMenu()
+{
+}
+
+void XGUI_HistoryMenu::setHistory(const QList<ActionInfo>& theActions)
+{
+ myHistoryList->clear();
+ foreach(ActionInfo anAct, theActions) {
+ QListWidgetItem* anItem = new QListWidgetItem(anAct.icon, anAct.text, myHistoryList);
+ }
+}
+
+
+void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
+{
+ if (!theItem)
+ return;
+
+ QListWidgetItem* eachItem = NULL;
+ bool isSelect = true;
+ for(int aRow = 0; aRow < myHistoryList->count(); ++aRow) {
+ eachItem = myHistoryList->item(aRow);
+ myHistoryList->setItemSelected(eachItem, isSelect);
+ // Deselect items below hovered
+ if (eachItem == theItem) {
+ isSelect = false;
+ }
+ }
+}
+
+void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
+{
+ int selectedSize = myHistoryList->row(theItem) + 1;
+ emit actionSelected(selectedSize);
+ hide();
+ myHistoryList->clear();
+}
--- /dev/null
+/*
+ * XGUI_HistoryMenu.h
+ *
+ * Created on: Feb 2, 2015
+ * Author: sbh
+ */
+
+#ifndef XGUI_HISTORYMENU_H_
+#define XGUI_HISTORYMENU_H_
+
+#include <XGUI.h>
+#include <QMenu>
+
+#include <ModuleBase_ActionInfo.h>
+
+class QListWidget;
+class QToolButton;
+class QListWidgetItem;
+
+class XGUI_EXPORT XGUI_HistoryMenu : public QMenu
+{
+ Q_OBJECT
+ public:
+ explicit XGUI_HistoryMenu(QToolButton* theParent);
+ explicit XGUI_HistoryMenu(QAction* theParent);
+ virtual ~XGUI_HistoryMenu();
+
+ signals:
+ void actionSelected(int);
+
+ public slots:
+ void setHistory(const QList<ActionInfo>&);
+
+ protected slots:
+ void setStackSelectedTo(QListWidgetItem *);
+ void onItemPressed(QListWidgetItem *);
+ void initMenu();
+
+ private:
+ QListWidget* myHistoryList;
+};
+
+#endif /* XGUI_OPERATIONSSTACKPOPUP_H_ */
QString aRes = aEditor->text();
ObjectPtr aFeature = mySelectedData.first();
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation();
+ aMgr->startOperation("RenameFeature");
aFeature->data()->setName(qPrintable(aRes));
aMgr->finishOperation();
}
#include <QString>
#include <QStringList>
+#include <ModuleBase_ActionInfo.h>
+
class QMainWindow;
class ModuleBase_IViewer;
const QString& theTitle, const QString& theTip, const QIcon& theIcon,
const QKeySequence& theKeys, bool isCheckable) = 0;
+ virtual QAction* addFeature(const QString& theWBName,
+ const ActionInfo& theInfo) = 0;
+
//! Creates a command in Edit menu of SALOME desktop
//! \param theId - an id of the feature
//! \param theTitle - a menu item string
{
myWorkshop->displayer()->updateViewer();
}
+
+//***************************************
+bool XGUI_ViewerProxy::canDragByMouse() const
+{
+ if (myWorkshop->isSalomeMode()) {
+ ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
+ return aViewer->canDragByMouse();
+ } else {
+ return true;
+ }
+}
\ No newline at end of file
/// Update current viewer
virtual void update();
+ /// Method returns True if the viewer can process editing objects
+ /// by mouse drugging. If this is impossible thet it has to return False.
+ virtual bool canDragByMouse() const;
+
private slots:
void onTryCloseView(AppElements_ViewWindow*);
void onDeleteView(AppElements_ViewWindow*);
#include "XGUI_ContextMenuMgr.h"
#include "XGUI_ModuleConnector.h"
#include <XGUI_QtEvents.h>
+#include <XGUI_HistoryMenu.h>
#include <AppElements_Workbench.h>
#include <AppElements_Viewer.h>
#include <QLayout>
#include <QThread>
#include <QObject>
+#include <QMenu>
+#include <QToolButton>
+#include <QAction>
#ifdef _DEBUG
#include <QDebug>
QIcon(":pictures/undo.png"),
QKeySequence::Undo, false, "MEN_DESK_EDIT");
connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
+ addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
+
aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
QIcon(":pictures/redo.png"), QKeySequence::Redo,
false, "MEN_DESK_EDIT");
connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
+ addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
+
salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
QIcon(":pictures/rebuild.png"), QKeySequence(),
aCommand->connectTo(this, SLOT(onSave()));
//aCommand->disable();
- aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
+ QString aUndoId = "UNDO_CMD";
+ aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
QIcon(":pictures/undo.png"), QKeySequence::Undo);
aCommand->connectTo(this, SLOT(onUndo()));
+ QToolButton* aUndoButton = qobject_cast<QToolButton*>(aGroup->widget(aUndoId));
+ addHistoryMenu(aUndoButton,
+ SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
+ SLOT(onUndo(int)));
- aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
+ QString aRedoId = "REDO_CMD";
+ aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
QIcon(":pictures/redo.png"), QKeySequence::Redo);
aCommand->connectTo(this, SLOT(onRedo()));
+ QToolButton* aRedoButton = qobject_cast<QToolButton*>(aGroup->widget(aRedoId));
+ addHistoryMenu(aRedoButton,
+ SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
+ SLOT(onRedo(int)));
aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
QIcon(":pictures/rebuild.png"), QKeySequence());
#endif
return;
}
+ ActionInfo aFeatureInfo;
+ aFeatureInfo.initFrom(theMessage);
// Remember features icons
- myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
+ myIcons[QString::fromStdString(theMessage->id())] = aFeatureInfo.iconFile;
- //Find or create Workbench
QString aWchName = QString::fromStdString(theMessage->workbenchId());
- QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
- bool isUsePropPanel = theMessage->isUseInput();
- QString aFeatureId = QString::fromStdString(theMessage->id());
+ QStringList aNestedFeatures =
+ QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
+ QString aDocKind = QString::fromStdString(theMessage->documentKind());
if (isSalomeMode()) {
- QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
- QString::fromStdString(theMessage->text()),
- QString::fromStdString(theMessage->tooltip()),
- QIcon(theMessage->icon().c_str()),
- QKeySequence(),
- isUsePropPanel);
- salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
- salomeConnector()->setDocumentKind(aFeatureId, QString::fromStdString(theMessage->documentKind()));
+ QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
+ salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
+ salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
myActionsMgr->addCommand(aAction);
myModule->actionCreated(aAction);
} else {
-
+ //Find or create Workbench
AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
if (!aPage) {
if (!aGroup) {
aGroup = aPage->addGroup(aGroupName);
}
- QString aDocKind = QString::fromStdString(theMessage->documentKind());
// Check if hotkey sequence is already defined:
- QKeySequence aHotKey = myActionsMgr->registerShortcut(
- QString::fromStdString(theMessage->keysequence()));
+ QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
+ if(aHotKey != aFeatureInfo.shortcut) {
+ aFeatureInfo.shortcut = aHotKey;
+ }
// Create feature...
- AppElements_Command* aCommand = aGroup->addFeature(aFeatureId,
- QString::fromStdString(theMessage->text()),
- QString::fromStdString(theMessage->tooltip()),
- QIcon(theMessage->icon().c_str()),
- aDocKind,
- aHotKey,
- isUsePropPanel);
- aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
+ AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo, aDocKind);
+ aCommand->setNestedCommands(aNestedFeatures);
myActionsMgr->addCommand(aCommand);
myModule->actionCreated(aCommand);
}
}
//******************************************************
-void XGUI_Workshop::onUndo()
+void XGUI_Workshop::onUndo(int theTimes)
{
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
SessionPtr aMgr = ModelAPI_Session::get();
if (aMgr->isOperation())
operationMgr()->onAbortOperation();
- aMgr->undo();
+ for (int i = 0; i < theTimes; ++i) {
+ aMgr->undo();
+ }
updateCommandStatus();
}
//******************************************************
-void XGUI_Workshop::onRedo()
+void XGUI_Workshop::onRedo(int theTimes)
{
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
SessionPtr aMgr = ModelAPI_Session::get();
if (aMgr->isOperation())
operationMgr()->onAbortOperation();
- aMgr->redo();
+ for (int i = 0; i < theTimes; ++i) {
+ aMgr->redo();
+ }
updateCommandStatus();
}
SessionPtr aMgr = ModelAPI_Session::get();
bool aWasOperation = aMgr->isOperation(); // keep this value
if (!aWasOperation) {
- aMgr->startOperation();
+ aMgr->startOperation("Rebuild");
}
static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
}
aUndoCmd->setEnabled(aMgr->canUndo() && !aMgr->isOperation());
aRedoCmd->setEnabled(aMgr->canRedo() && !aMgr->isOperation());
+
+ updateHistory();
+
} else {
foreach(QAction* aCmd, aCommands) {
QString aId = aCmd->data().toString();
emit commandStatusUpdated();
}
+void XGUI_Workshop::updateHistory()
+{
+ std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
+ std::list<std::string>::iterator it = aUndoList.begin();
+ QList<ActionInfo> aUndoRes;
+ for ( ; it != aUndoList.end(); it++) {
+ QString anId = QString::fromStdString(*it);
+ QIcon aIcon;
+ if (myIcons.contains(anId))
+ aIcon = QIcon(myIcons[anId]);
+ aUndoRes << ActionInfo(aIcon, anId);
+ }
+ emit updateUndoHistory(aUndoRes);
+
+ std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
+ it = aRedoList.begin();
+ QList<ActionInfo> aRedoRes;
+ for ( ; it != aRedoList.end(); it++) {
+ QString anId = QString::fromStdString(*it);
+ QIcon aIcon;
+ if (myIcons.contains(anId))
+ aIcon = QIcon(myIcons[anId]);
+ aRedoRes << ActionInfo(aIcon, anId);
+ }
+ emit updateRedoHistory(aUndoRes);
+}
+
//******************************************************
QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
{
}
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation();
+ aMgr->startOperation("DeleteObjects");
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
for (; anIt != aLast; anIt++) {
} else
myDisplayer->display(theObj, false);
}
+
+void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
+{
+ XGUI_HistoryMenu* aMenu = NULL;
+ if (isSalomeMode()) {
+ QAction* anAction = qobject_cast<QAction*>(theObject);
+ if (!anAction)
+ return;
+ aMenu = new XGUI_HistoryMenu(anAction);
+ } else {
+ QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
+ aMenu = new XGUI_HistoryMenu(aButton);
+ }
+ connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
+ connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
+
+}
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
+#include <ModuleBase_ActionInfo.h>
+
#include <QObject>
#include <QMap>
#include <QKeySequence>
//! the application is started
void applicationStarted();
+ void updateUndoHistory(const QList<ActionInfo>&);
+ void updateRedoHistory(const QList<ActionInfo>&);
+
public slots:
/// Update of commands status
void updateCommandStatus();
+ /// update history list (undo/redo commands)
+ void updateHistory();
+
/// Create a new dokument
void onNew();
void onExit();
/// Undo last command
- void onUndo();
+ void onUndo(int times = 1);
/// Redo previous command
- void onRedo();
+ void onRedo(int times = 1);
/// Rebuild data tree
void onRebuild();
/// Displaus object and fit all viewer if the object is first (update viewer will not be called)
void displayObject(ObjectPtr theObj);
+ //! Extends undo/redo toolbutton's with history menu
+ //! \param theObject - in the OpenParts it is a QToolButton by itself,
+ //! in salome mode - QAction that creates a button.
+ //! \param theSignal - void "updateUndoHistory" or "updateRedoHistory" SIGNAL;
+ //! \param theSlot - onUndo(int) or onRedo(int) SLOT
+ void addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot);
+
private:
AppElements_MainWindow* myMainWindow;
ModuleBase_IModule* myModule;