#include "PartSet_CustomPrs.h"
#include "PartSet_IconFactory.h"
#include "PartSet_WidgetChoice.h"
+#include "PartSet_OverconstraintListener.h"
#include "PartSet_Filters.h"
#include "PartSet_FilterInfinite.h"
#include <ModuleBase_FilterFactory.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_OperationDescription.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Events.h>
#include <XGUI_SelectionMgr.h>
#include <XGUI_DataModel.h>
#include <XGUI_ErrorMgr.h>
+#include <XGUI_CustomPrs.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_Sketch.h>
#include <QMessageBox>
#include <QMainWindow>
#include <QLineEdit>
+#include <QString>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomDataAPI_Dir.h>
myMenuMgr = new PartSet_MenuMgr(this);
myCustomPrs = new PartSet_CustomPrs(theWshop);
+ myOverconstraintListener = new PartSet_OverconstraintListener(theWshop);
+
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
myHasConstraintShown[PartSet_Tools::Geometrical] = true;
myHasConstraintShown[PartSet_Tools::Dimensional] = true;
+
+ Config_PropManager::registerProp("Visualization", "operation_parameter_color",
+ "Reference shape wireframe color in operation", Config_Prop::Color,
+ PartSet_CustomPrs::OPERATION_PARAMETER_COLOR());
+ Config_PropManager::registerProp("Visualization", "operation_result_color",
+ "Result shape wireframe color in operation", Config_Prop::Color,
+ PartSet_CustomPrs::OPERATION_RESULT_COLOR());
+ Config_PropManager::registerProp("Visualization", "operation_highlight_color",
+ "Multi selector item color in operation", Config_Prop::Color,
+ PartSet_CustomPrs::OPERATION_HIGHLIGHT_COLOR());
}
PartSet_Module::~PartSet_Module()
aFilter.Nullify();
}
delete myCustomPrs;
+ delete myOverconstraintListener;
}
void PartSet_Module::activateSelectionFilters()
aFactory->registerValidator("PartSet_FilletSelection", new PartSet_FilletSelection);
aFactory->registerValidator("PartSet_AngleSelection", new PartSet_AngleSelection);
aFactory->registerValidator("PartSet_EqualSelection", new PartSet_EqualSelection);
+ aFactory->registerValidator("PartSet_CollinearSelection", new PartSet_CollinearSelection);
+ aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection);
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr);
aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator);
// the selection is cleared after commit the create operation
// in order to do not use the same selected objects in the restarted operation
// for common behaviour, the selection is cleared even if the operation is not restarted
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
- XGUI_Workshop* aWorkshop = aConnector->workshop();
- aWorkshop->selector()->clearSelection();
+ getWorkshop()->selector()->clearSelection();
}
}
}
}
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
- if (aFOperation)
- myCustomPrs->activate(aFOperation->feature(), true);
+ if (aFOperation) {
+ myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
+ myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
+ }
}
void PartSet_Module::operationResumed(ModuleBase_Operation* theOperation)
ModuleBase_IModule::operationResumed(theOperation);
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
- if (aFOperation)
- myCustomPrs->activate(aFOperation->feature(), true);
+ if (aFOperation) {
+ myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeArguments, true);
+ myCustomPrs->activate(aFOperation->feature(), ModuleBase_IModule::CustomizeResults, true);
+ }
}
void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation)
{
- bool isModified = myCustomPrs->deactivate(false);
+ bool isModified = myCustomPrs->deactivate(ModuleBase_IModule::CustomizeArguments, false) ||
+ myCustomPrs->deactivate(ModuleBase_IModule::CustomizeResults, false);
if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
mySketchMgr->stopNestedSketch(theOperation);
return mySketchMgr->canDisplayObject(theObject);
}
+void PartSet_Module::processHiddenObject(const std::list<ObjectPtr>& theObjects)
+{
+ mySketchMgr->processHiddenObject(theObjects);
+}
+
bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const
{
bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject);
myMenuMgr->grantedOperationIds(theOperation, theIds);
if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
- XGUI_Workshop* aWorkshop = aConnector->workshop();
-
+ XGUI_Workshop* aWorkshop = getWorkshop();
theIds.append(aWorkshop->contextMenuMgr()->action("DELETE_CMD")->text());
}
}
{
myCustomPrs->clearPrs();
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Workshop* aWorkshop = getWorkshop();
XGUI_Displayer* aDisplayer = aWorkshop->displayer();
aDisplayer->deactivateSelectionFilters();
}
aPanel->activateWidget(aPanel->modelWidgets().first());
}
+bool PartSet_Module::createWidgets(ModuleBase_Operation* theOperation,
+ QList<ModuleBase_ModelWidget*>& theWidgets) const
+{
+ bool aProcessed = false;
+
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ XGUI_Workshop* aWorkshop = getWorkshop();
+ XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
+ if (mySketchMgr->activeSketch().get() && aFOperation && aPropertyPanel) {
+ ModuleBase_ISelection* aSelection = workshop()->selection();
+ // click on a point in sketch leads here with the point is highlighted, not yet selected
+ QList<ModuleBase_ViewerPrs> aPreselection = aSelection->getHighlighted();
+ if (aPreselection.size() == 1) {
+ ModuleBase_ViewerPrs aSelectedPrs = aPreselection[0];
+ ObjectPtr anObject = aSelectedPrs.object();
+
+ FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
+ FeaturePtr anOpFeature = aFOperation->feature();
+ TopoDS_Shape aShape = aSelectedPrs.shape();
+ // click on the digit of dimension constrain comes here with an empty shape, so we need the check
+ if (aFeature == anOpFeature && !aShape.IsNull()) {
+ AttributePtr anAttribute = PartSet_Tools::findAttributeBy2dPoint(anObject, aShape,
+ mySketchMgr->activeSketch());
+ if (anAttribute.get()) {
+ QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
+ ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), workshop());
+
+ const std::string anAttributeId = anAttribute->id();
+ aFactory.createWidget(aPropertyPanel->contentWidget(), anAttributeId);
+
+ theWidgets = aFactory.getModelWidgets();
+ // it is possible that the point does not present in XML definition,
+ // in this case, we assume that it is not processed by this module
+ // e.g. "Intersection point" feature
+ aProcessed = !theWidgets.isEmpty();
+ }
+ }
+ }
+ }
+ return aProcessed;
+}
void PartSet_Module::onSelectionChanged()
{
{
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr();
- anOpMgr->onKeyReleased(theEvent);
+ anOpMgr->onKeyReleased(theWnd->viewPort(), theEvent);
}
void PartSet_Module::onOperationActivatedByPreselection()
Config_WidgetAPI* theWidgetApi, std::string theParentId)
{
ModuleBase_IWorkshop* aWorkshop = workshop();
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
- XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
+ XGUI_Workshop* aXUIWorkshop = getWorkshop();
ModuleBase_ModelWidget* aWgt = NULL;
if (theType == "sketch-start-label") {
PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
{
bool isProcessed = false;
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
- XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Workshop* aWorkshop = getWorkshop();
XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr();
//SessionPtr aMgr = ModelAPI_Session::get();
//Handle(V3d_View) aView = aViewer->activeView();
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Workshop* aWorkshop = getWorkshop();
XGUI_Displayer* aDisplayer = aWorkshop->displayer();
Handle(V3d_Viewer) aV3dViewer = aContext->CurrentViewer();
Handle(V3d_View) aView;
}
if (aView.IsNull())
return;
- double aLen = aView->Convert(20);
+ double aLen = aView->Convert(SketcherPrs_Tools::getDefaultArrowSize());
double aPrevLen = SketcherPrs_Tools::getArrowSize();
SketcherPrs_Tools::setArrowSize(aLen);
aDisplayer->updateViewer();
}
+void PartSet_Module::activateCustomPrs(const FeaturePtr& theFeature, const ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
+{
+ myCustomPrs->activate(theFeature, theFlag, theUpdateViewer);
+}
+
+void PartSet_Module::deactivateCustomPrs(const ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
+{
+ myCustomPrs->deactivate(theFlag, theUpdateViewer);
+}
+
+bool PartSet_Module::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
+{
+ bool aCustomized = false;
+
+ if (theResult.get())
+ return aCustomized;
+
+ XGUI_Workshop* aWorkshop = getWorkshop();
+ XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+ ObjectPtr anObject = aDisplayer->getObject(thePrs);
+ if (anObject.get()) {
+ bool isConflicting = myOverconstraintListener->isConflictingObject(anObject);
+ // customize sketcy symbol presentation
+ if (thePrs.get()) {
+ Handle(AIS_InteractiveObject) anAISIO = thePrs->impl<Handle(AIS_InteractiveObject)>();
+ if (!anAISIO.IsNull()) {
+ if (!Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO).IsNull()) {
+ Handle(SketcherPrs_SymbolPrs) aPrs = Handle(SketcherPrs_SymbolPrs)::DownCast(anAISIO);
+ if (!aPrs.IsNull()) {
+ std::vector<int> aColor;
+ myOverconstraintListener->getConflictingColor(aColor);
+ aPrs->SetConflictingConstraint(isConflicting, aColor);
+ aCustomized = true;
+ }
+ }
+ }
+ }
+ // customize sketch dimension constraint presentation
+ if (!aCustomized) {
+ std::vector<int> aColor;
+ if (isConflicting) {
+ myOverconstraintListener->getConflictingColor(aColor);
+ }
+ if (aColor.empty())
+ XGUI_CustomPrs::getDefaultColor(anObject, true, aColor);
+ if (!aColor.empty()) {
+ thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+ aCustomized = true;
+ }
+ }
+ }
+
+ return aCustomized;
+}
+
bool PartSet_Module::customizeObject(ObjectPtr theObject, const ModuleBase_CustomizeFlag& theFlag,
const bool theUpdateViewer)
{
bool isRedisplayed = false;
- if (myCustomPrs->isActive())
+ if (myCustomPrs->isActive(theFlag))
isRedisplayed = myCustomPrs->redisplay(theObject, theFlag, theUpdateViewer);
return isRedisplayed;
SessionPtr aMgr = ModelAPI_Session::get();
QAction* aActivatePartAction = myMenuMgr->action("ACTIVATE_PARTSET_CMD");
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Workshop* aWorkshop = getWorkshop();
QLabel* aHeader = aWorkshop->objectBrowser()->activeDocLabel();
aActivatePartAction->setEnabled((aMgr->activeDocument() != aMgr->moduleDocument()));
if (aOperation) {
/// If last line finished on vertex the lines creation sequence has to be break
ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
- ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
- // if there is an active widget, find the presented object in it
- if (!anActiveWidget)
- anActiveWidget = aPanel->preselectionWidget();
+ if (aPanel) {
+ ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+ // if there is an active widget, find the presented object in it
+ if (!anActiveWidget)
+ anActiveWidget = aPanel->preselectionWidget();
- ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
- (anActiveWidget);
- if (aWidgetValidated)
- anObject = aWidgetValidated->findPresentedObject(theAIS);
+ ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast<ModuleBase_WidgetValidated*>
+ (anActiveWidget);
+ if (aWidgetValidated)
+ anObject = aWidgetValidated->findPresentedObject(theAIS);
+ }
}
return anObject;
}
if (myWorkshop->currentOperation() &&
(!aAllowActivationList.contains(myWorkshop->currentOperation()->id())))
return;
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Workshop* aWorkshop = getWorkshop();
XGUI_DataTree* aTreeView = aWorkshop->objectBrowser()->treeView();
QLabel* aLabel = aWorkshop->objectBrowser()->activeDocLabel();
QPalette aPalet = aLabel->palette();
if (theIndex.column() != 0) // Use only first column
return;
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
+ XGUI_Workshop* aWorkshop = getWorkshop();
XGUI_DataModel* aDataModel = aWorkshop->objectBrowser()->dataModel();
// De not use non editable Indexes
if ((aDataModel->flags(theIndex) & Qt::ItemIsSelectable) == 0)
}
}
+//******************************************************
+GeomShapePtr PartSet_Module::findShape(const AttributePtr& theAttribute)
+{
+ GeomShapePtr aGeomShape;
+
+ ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+ if (anOperation && PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) {
+ aGeomShape = PartSet_Tools::findShapeBy2DPoint(theAttribute, myWorkshop);
+ }
+ return aGeomShape;
+}
+
+//******************************************************
+AttributePtr PartSet_Module::findAttribute(const ObjectPtr& theObject,
+ const GeomShapePtr& theGeomShape)
+{
+ AttributePtr anAttribute;
+ GeomShapePtr aGeomShape = theGeomShape;
+ if (!aGeomShape.get()) {
+ // processing shape of result, e.g. sketch circle center is selected, this is a result
+ // the geom shape is empty, the shape of result should be used
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aResult.get()) {
+ aGeomShape = aResult->shape();
+ }
+ }
+
+ if (aGeomShape.get()) {
+ TopoDS_Shape aTDSShape = aGeomShape->impl<TopoDS_Shape>();
+ return PartSet_Tools::findAttributeBy2dPoint(theObject, aTDSShape,
+ mySketchMgr->activeSketch());
+ }
+ return anAttribute;
+}
+
//******************************************************
void PartSet_Module::onBooleanOperationChange(int theOperation)
{
break;
}
}
+
+//******************************************************
+XGUI_Workshop* PartSet_Module::getWorkshop() const
+{
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+ return aConnector->workshop();
+}