/// \param theObject a model object\r
virtual bool canDisplayObject(const ObjectPtr& theObject) const;\r
\r
+ /// Reacts to the delete action in module\r
+ /// \returns true if the action is processed\r
+ virtual bool deleteObjects() { return false; };\r
+\r
public slots:\r
/// Called on call of command corresponded to a feature\r
void onFeatureTriggered();\r
return isValid();
}
-void ModuleBase_Operation::flushUpdated()
-{
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-}
-
-void ModuleBase_Operation::flushCreated()
-{
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-}
-
FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
{
if (myParentFeature.get()) {
}
if (theFlushMessage)
- flushCreated();
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
return myFeature;
}
/// Virtual method called after operation resume (see resume() method for more description)
virtual void resumeOperation() {}
- /// Send update message by loop
- void flushUpdated();
-
- /// Send created message by loop
- void flushCreated();
-
/// Creates an operation new feature
/// \param theFlushMessage the flag whether the create message should be flushed
/// \returns the created feature
ModuleBase_Tools::zeroMargins(aLay);
QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg);
+ aEditor->selectAll();
aEditor->setValidator(new QDoubleValidator(aEditor));
QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept()));
aLay->addWidget(aEditor);
if (!myObjectTypes.isEmpty() && myObjTypeFilter.IsNull()) {
myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
}
- theFilters.Append(myObjTypeFilter);
+ if (!myObjTypeFilter.IsNull())
+ theFilters.Append(myObjTypeFilter);
// apply filters loaded from the XML definition of the widget
ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
#include <XGUI_OperationMgr.h>
#include <XGUI_PropertyPanel.h>
#include <XGUI_ModuleConnector.h>
+#include <XGUI_ContextMenuMgr.h>
#include <XGUI_Tools.h>
#include <SketchPlugin_Feature.h>
XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased()));
- connect(anOpMgr, SIGNAL(keyDeleteReleased()), this, SLOT(onDeleteObjects()));
connect(anOpMgr, SIGNAL(operationActivatedByPreselection()),
this, SLOT(onOperationActivatedByPreselection()));
hasFeature = true;
}
}
- if (hasFeature)
- theMenu->addAction(action("DELETE_PARTSET_CMD"));
+ if (hasFeature) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
+ QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD");
+ theMenu->addAction(anAction);
+ }
+ }
+ bool isConstruction;
+ if (mySketchMgr->canChangeConstruction(isConstruction)) {
+ QAction* anAction = action("CONSTRUCTION_CMD");
+ theMenu->addAction(anAction);
+ anAction->setChecked(isConstruction);
}
}
myRestartingMode = RM_EmptyFeatureUsed;
}
-void PartSet_Module::onDeleteObjects()
-{
- ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
- if (PartSet_SketcherMgr::isSketchOperation(anOperation) ||
- PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
- deleteObjects();
-}
-
void PartSet_Module::onOperationActivatedByPreselection()
{
ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
void PartSet_Module::createActions()
{
- QAction* aAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this);
- addAction("DELETE_PARTSET_CMD", aAction);
+ QAction* anAction;
+
+ anAction = new QAction(tr("Construction"), this);
+ anAction->setCheckable(true);
+ addAction("CONSTRUCTION_CMD", anAction);
}
QAction* PartSet_Module::action(const QString& theId) const
QAction* aAction = static_cast<QAction*>(sender());
QString anId = aAction->data().toString();
- if (anId == "DELETE_PARTSET_CMD") {
- deleteObjects();
+ if (anId == "CONSTRUCTION_CMD") {
+ mySketchMgr->setConstruction(isChecked);
}
}
-void PartSet_Module::deleteObjects()
+bool PartSet_Module::deleteObjects()
{
ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
- bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation);
- if (!isSketchOp && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
- return;
+ bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation),
+ isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+ if (!isSketchOp && !isNestedOp)
+ return false;
// sketch feature should be skipped, only sub-features can be removed
// when sketch operation is active
// selected objects should be collected before the current operation abort because
// the abort leads to selection lost on constraint objects. It can be corrected after #386 issue
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+ XGUI_Workshop* aWorkshop = aConnector->workshop();
ModuleBase_ISelection* aSel = aConnector->selection();
QObjectPtrList aSelectedObj = aSel->selectedPresentations();
- XGUI_Workshop* aWorkshop = aConnector->workshop();
- XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
- if (!isSketchOp && anOpMgr->canStopOperation()) {
- ModuleBase_Operation* aCurrentOp = anOpMgr->currentOperation();
- if (aCurrentOp) {
- aCurrentOp->abort();
- }
- }
+ // if there are no selected objects in the viewer, that means that the selection in another
+ // place cased this method. It is necessary to return the false value to understande in above
+ // method that delete is not processed
+ if (aSelectedObj.count() == 0)
+ return false;
+
+ if (isNestedOp)
+ anOperation->abort();
+
+ // the active nested sketch operation should be aborted unconditionally
+ if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+ anOperation->abort();
+
std::set<FeaturePtr> aRefFeatures;
foreach (ObjectPtr aObj, aSelectedObj)
{
}
//}
}
- QString aDescription = tr("Delete");
+
+ QString aDescription = aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text();
/**
// according to #355 feature, it is not necessary to inform about dependencies during
// sketch delete operation
aWorkshop->displayer()->updateViewer();
//myDisplayer->updateViewer();
aMgr->finishOperation();
+
+ return true;
}
/// \param theOperation a stopped operation
virtual void operationStopped(ModuleBase_Operation* theOperation);
+ /// Returns action according to the given ID
+ /// \param theId an action identifier, it should be uniqued in the bounds of the module
+ QAction* action(const QString& theId) const;
+
/// Returns True if there are available Undos and the sketch manager allows undo
/// \return the boolean result
virtual bool canUndo() const;
/// It commits the operation of it is can be committed
void onOperationActivatedByPreselection();
- //! Delete features
- void onDeleteObjects();
-
protected:
/// Register validators for this module
virtual void registerValidators();
/// Put the created actions into an internal map
void createActions();
- /// Returns action according to the given ID
- /// \param theId an action identifier, it should be uniqued in the bounds of the module
- QAction* action(const QString& theId) const;
-
/// Add action to the internal map
/// \param theId - string ID of the item
/// \param theAction - action to add
void addAction(const QString& theId, QAction* theAction);
//! Delete features
- void deleteObjects();
+ virtual bool deleteObjects();
private:
QString myLastOperationId;
#include <XGUI_ModuleConnector.h>
#include <XGUI_Displayer.h>
#include <XGUI_Workshop.h>
+#include <XGUI_ContextMenuMgr.h>
#include <XGUI_Selection.h>
#include <XGUI_SelectionMgr.h>
#include <ModuleBase_ModelWidget.h>
//#include <AIS_Shape.hxx>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Session.h>
#include <QMouseEvent>
#include <QApplication>
PartSet_SketcherMgr::sketchOperationIdList().contains(theOperation->id());
}
+bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
+{
+ return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
+}
+
+bool PartSet_SketcherMgr::isEntityOperation(ModuleBase_Operation* theOperation)
+{
+ std::string aId = theOperation ? theOperation->id().toStdString() : "";
+
+ return (aId == SketchPlugin_Line::ID()) ||
+ (aId == SketchPlugin_Point::ID()) ||
+ (aId == SketchPlugin_Arc::ID()) ||
+ (aId == SketchPlugin_Circle::ID());
+}
+
bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
{
std::string aId = theOperation ? theOperation->id().toStdString() : "";
return aCanDisplay;
}
+bool PartSet_SketcherMgr::canChangeConstruction(bool& isConstruction) const
+{
+ bool anEnabled = false;
+ ModuleBase_Operation* anOperation = getCurrentOperation();
+
+ bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
+ PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+ if (!isActiveSketch)
+ return anEnabled;
+
+ QObjectPtrList anObjects;
+ // 1. change construction type of a created feature
+ if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+ PartSet_SketcherMgr::isEntityOperation(anOperation) ) {
+ anObjects.append(anOperation->feature());
+ }
+ else {
+ if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+ anOperation->abort();
+ // 2. change construction type of selected sketch entities
+ ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
+ anObjects = aSelection->selectedPresentations();
+ }
+ anEnabled = anObjects.size() > 0;
+
+ bool isNotConstructedFound = false;
+ if (anObjects.size() > 0) {
+ QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
+ for (; anIt != aLast && !isNotConstructedFound; anIt++) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ if (aFeature.get() != NULL) {
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSketchFeature.get() != NULL) {
+ std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+
+ std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+ isNotConstructedFound = !aConstructionAttr->value();
+ }
+ }
+ }
+ }
+ isConstruction = anObjects.size() && !isNotConstructedFound;
+ return anEnabled;
+}
+
+void PartSet_SketcherMgr::setConstruction(const bool isChecked)
+{
+ ModuleBase_Operation* anOperation = getCurrentOperation();
+
+ bool isActiveSketch = PartSet_SketcherMgr::isSketchOperation(anOperation) ||
+ PartSet_SketcherMgr::isNestedSketchOperation(anOperation);
+ if (!isActiveSketch)
+ return;
+
+ QObjectPtrList anObjects;
+ bool isUseTransaction = false;
+ // 1. change construction type of a created feature
+ if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+ PartSet_SketcherMgr::isEntityOperation(anOperation) ) {
+ anObjects.append(anOperation->feature());
+ }
+ else {
+ isUseTransaction = true;
+ // 2. change construction type of selected sketch entities
+ ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
+ anObjects = aSelection->selectedPresentations();
+ }
+
+ QAction* anAction = myModule->action("CONSTRUCTION_CMD");
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (isUseTransaction) {
+ if (PartSet_SketcherMgr::isNestedSketchOperation(anOperation))
+ anOperation->abort();
+ aMgr->startOperation(anAction->text().toStdString());
+ }
+ storeSelection();
+
+ if (anObjects.size() > 0) {
+ QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+ if (aFeature.get() != NULL) {
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+ if (aSketchFeature.get() != NULL) {
+ std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+
+ std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
+ aConstructionAttr->setValue(isChecked);
+ }
+ }
+ }
+ }
+ if (isUseTransaction) {
+ aMgr->finishOperation();
+ }
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ restoreSelection();
+}
+
void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln)
{
myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
return myModule->workshop()->currentOperation();
}
-bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation) const
-{
- return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
-}
-
void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
const bool isToDisplay)
{
void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly)
{
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
-
ModuleBase_ISelection* aSelect = aWorkshop->selection();
QList<ModuleBase_ViewerPrs> aHighlighted = aSelect->getHighlighted();
FeaturePtr aFeature = anIt.key();
getCurrentSelection(aFeature, myCurrentSketch, aWorkshop, myCurrentSelection);
}
- qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+ //qDebug(QString(" storeSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
}
void PartSet_SketcherMgr::restoreSelection()
{
- qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
+ //qDebug(QString("restoreSelection: %1").arg(myCurrentSelection.size()).toStdString().c_str());
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
/// \return the boolean result
static bool isNestedSketchOperation(ModuleBase_Operation* theOperation);
- /// Returns whethe the current operation is a sketch distance - lenght, distance or radius
+ /// Returns true if the operation is a create nested feature one
+ /// \param theOperation a checked operation
+ //// \return boolean value
+ static bool isNestedCreateOperation(ModuleBase_Operation* theOperation);
+
+ /// Returns whether the current operation is a sketch entity - line, point, arc or circle
+ /// \param the operation
+ /// \return a boolean value
+ static bool isEntityOperation(ModuleBase_Operation* theOperation);
+
+ /// Returns whether the current operation is a sketch distance - lenght, distance or radius
/// \param the operation
/// \return a boolean value
static bool isDistanceOperation(ModuleBase_Operation* theOperation);
/// \param theObject a model object
bool canDisplayObject() const;
+ /// Returns true if the current operation is sketch entity create operation
+ /// \param isConstruction the current construction state
+ /// \return the boolean result
+ bool canChangeConstruction(bool& isConstruction) const;
+
+ /// Changes the sketcher entity construction argument value
+ /// \param isChecked if true, the feature is a construction
+ void setConstruction(const bool isChecked);
+
public slots:
/// Process sketch plane selected event
void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
/// \return an operation
ModuleBase_Operation* getCurrentOperation() const;
- /// Returns true if the operation is a create nested feature one
- /// \param theOperation a checked operation
- //// \return boolean value
- bool isNestedCreateOperation(ModuleBase_Operation* theOperation) const;
-
/// Erase or display the feature of the current operation. If the mouse over the active view or
/// a current value is changed by property panel, the feature is displayed otherwise it is hidden
/// \param theOperation an operation which feature is to be displayed, it is nested create operation
const std::string& theParentId)
: ModuleBase_ModelWidget(theParent, theData, theParentId)
{
+ // the control should accept the focus, so the boolen flag is corrected to be true
+ myIsObligatory = true;
//myOptionParam = theData->getProperty(PREVIOUS_FEATURE_PARAM);
QString aPageName = QString::fromStdString(theData->getProperty(CONTAINER_PAGE_NAME));
myGroupBox = new QGroupBox(aPageName, theParent);
void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
+ // the contex menu release by the right button should not be processed by this widget
+ if (theEvent->button() != Qt::LeftButton)
+ return;
+
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.
if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
return;
- bool isConstruction = data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value();
+ std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
+ data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID());
+ bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
if (aShapeType == 6) { // if this is an edge
if (isConstruction) {
thePrs->setWidth(1);
+ thePrs->setLineStyle(3);
aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
SKETCH_CONSTRUCTION_COLOR);
}
else {
thePrs->setWidth(3);
+ thePrs->setLineStyle(0);
if (isExternal()) {
// Set color from preferences
aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
if (aFeature->data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value())
continue;
}
+ // do not include the construction entities in the result
+ if (aFeature->data()->attribute(SketchPlugin_Feature::CONSTRUCTION_ID())) {
+ if (aFeature->data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value())
+ continue;
+ }
const std::list<std::shared_ptr<ModelAPI_Result> >& aRes = aFeature->results();
std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter = aRes.cbegin();
// Check that the visualized shape is the same and the redisplay is not necessary
// Redisplay of AIS object leads to this object selection compute and the selection
// in the browser is lost
- // become
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+
+ // this check is not necessary anymore because the selection store/restore is realized
+ // before and after the values modification.
+ // Moreother, this check avoids customize and redisplay presentation if the presentable
+ // parameter is changed.
+ /*ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (aResult.get() != NULL) {
Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aAISIO);
if (!aShapePrs.IsNull()) {
return;
}
}
+ }*/
+ // Customization of presentation
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ if (aFeature.get() != NULL) {
+ GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+ if (aCustPrs.get() != NULL)
+ aCustPrs->customisePresentation(aAISObj);
}
+
aContext->Redisplay(aAISIO, false);
if (isUpdateViewer)
updateViewer();
commitOperation();
}
break;
- case Qt::Key_Delete: { // the delete button is occupied by the workshop Delete action,
- // so this button process is realized here
- emit keyDeleteReleased();
- }
default:
isAccepted = false;
break;
/// Signal is emitted after the key released click.
void keyEnterReleased();
- /// Signal is emitted after the key delete released click.
- void keyDeleteReleased();
-
protected:
/// Commits the current operatin if it is valid
bool commitOperation();
//**************************************************************
void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList)
{
- // the active operation should not be aborted if there is an empty list of objects
- // it is possible that delete shortcut should be processed in the active operation.
- if (theList.empty())
+ ModuleBase_IModule* aModule = module();
+ if (aModule->deleteObjects())
return;
if (!isActiveOperationAborted())