Construction change through a context popup menu.
Customize presentation by redisplay feature
#include <XGUI_OperationMgr.h>
#include <XGUI_PropertyPanel.h>
#include <XGUI_ModuleConnector.h>
+#include <XGUI_ContextMenuMgr.h>
#include <XGUI_Tools.h>
#include <SketchPlugin_Feature.h>
hasFeature = true;
}
}
- if (hasFeature)
+ 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);
theMenu->addAction(action("DELETE_PARTSET_CMD"));
+ }
+ }
+ bool isConstruction;
+ if (mySketchMgr->canChangeConstruction(isConstruction)) {
+ QAction* anAction = action("CONSTRUCTION_CMD");
+ theMenu->addAction(anAction);
+ anAction->setChecked(isConstruction);
}
}
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(QIcon(":pictures/delete.png"), tr("Delete"), this);
+ addAction("DELETE_PARTSET_CMD", anAction);
+
+ anAction = new QAction(tr("Construction"), this);
+ anAction->setCheckable(true);
+ addAction("CONSTRUCTION_CMD", anAction);
}
QAction* PartSet_Module::action(const QString& theId) const
if (anId == "DELETE_PARTSET_CMD") {
deleteObjects();
}
+ if (anId == "CONSTRUCTION_CMD") {
+ mySketchMgr->setConstruction(isChecked);
+ }
}
void PartSet_Module::deleteObjects()
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
+{
+ ModuleBase_Operation* anOperation = getCurrentOperation();
+
+ bool anEnabled = PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
+ PartSet_SketcherMgr::isEntityOperation(anOperation);
+ if (anEnabled) {
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(anOperation->feature());
+ 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));
+
+ isConstruction = aConstructionAttr->value();
+ }
+ }
+ return anEnabled;
+}
+
+void PartSet_SketcherMgr::setConstruction(const bool isChecked)
+{
+ ModuleBase_Operation* anOperation = getCurrentOperation();
+ std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(anOperation->feature());
+ 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);
+
+ // ModuleBase_ModelWidget::updateObject
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(aSketchFeature, anEvent);
+ Events_Loop::loop()->flush(anEvent);
+ }
+}
+
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)
{
/// \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
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) { // 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",
// 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();