#include <memory>
class Config_WidgetAPI;
+class ModuleBase_IWorkshop;
class QKeyEvent;
/**\class ModuleBase_ModelWidget
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
/// \param theValues the wrapped selection values
- virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues)
+ /// \param toValidate the boolean value whether the value should be checked by filters
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate)
{
return false;
}
if (!aWgt->canSetValue())
continue;
- if (!aWgt->setSelection(myPreSelection)) {
+ if (!aWgt->setSelection(myPreSelection, true)) {
isSet = false;
break;
} else {
}
//********************************************************************
-bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
+bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate)
{
QList<ModuleBase_ViewerPrs> aSkippedValues;
for (; anIt != aLast; anIt++) {
ModuleBase_ViewerPrs aValue = *anIt;
bool aProcessed = false;
- if (isValidSelection(aValue)) {
+ if (!theToValidate || isValidInFilters(aValue)) {
aProcessed = setSelectionCustom(aValue);
}
else
void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
{
activateSelection(true);
- activateFilters(myWorkshop, true);
+ activateFilters(true);
QList<ModuleBase_ViewerPrs> anEmptyList;
// This method will call Selection changed event which will call onSelectionChanged
// To clear mySelection, myListControl and storeValue()
TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
activateSelection(false);
- activateFilters(myWorkshop, false);
+ activateFilters(false);
bool isBlocked = myTypeCombo->blockSignals(true);
myTypeCombo->setCurrentIndex(idx);
myTypeCombo->blockSignals(isBlocked);
activateSelection(true);
- activateFilters(myWorkshop, true);
+ activateFilters(true);
break;
}
}
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
/// \param theValues the wrapped selection values
- virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate);
/// Checks the widget validity. By default, it returns true.
/// \param theValue a selected presentation in the view
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_WidgetValidated(theParent, theData, theParentId),
- myWorkshop(theWorkshop)
+ : ModuleBase_WidgetValidated(theParent, theWorkshop, theData, theParentId)
{
}
QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
ModuleBase_ISelection::AllControls);
- bool isDone = setSelection(aSelected);
+ bool isDone = setSelection(aSelected, true);
emit valuesChanged();
// the updateObject method should be called to flush the updated sigal. The workshop listens it,
// Restore selection in the viewer by the attribute selection list
myWorkshop->setSelected(getAttributeSelection());
- activateFilters(myWorkshop, true);
+ activateFilters(true);
}
//********************************************************************
-#include <ModuleBase_IViewer.h>
-#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
-#include <StdSelect_BRepOwner.hxx>
bool ModuleBase_WidgetSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aResult);
aValid = aSelectedFeature != myFeature;
}
-
- // selection happens in the Object browser.
- // it creates a selection owner and check whether the viewer filters process it
- if (thePrs.owner().IsNull() && thePrs.object().get()) {
- ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
- if (aResult.get())
- aShape = aResult->shape();
-
- const TopoDS_Shape aTDShape = aShape->impl<TopoDS_Shape>();
-
- Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
- Handle(StdSelect_BRepOwner) aShapeOwner = new StdSelect_BRepOwner(aTDShape, anIO);
-
- const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters();
- SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
- for (; anIt.More() && aValid; anIt.Next()) {
- Handle(SelectMgr_Filter) aFilter = anIt.Value();
- if (aFilter == myWorkshop->validatorFilter())
- continue;
-
- aValid = aFilter->IsOk(aShapeOwner);
- }
- aShapeOwner.Nullify();
- }
return aValid;
}
{
disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
activateSelection(false);
- activateFilters(myWorkshop, false);
+ activateFilters(false);
}
GeomShapePtr& theShape);
//----------- Class members -------------
-protected:
- /// Reference to workshop
- ModuleBase_IWorkshop* myWorkshop;
};
#endif
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
#include <SelectMgr_EntityOwner.hxx>
+#include <StdSelect_BRepOwner.hxx>
#include <Events_Loop.h>
//#define DEBUG_VALID_STATE
ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId)
- : ModuleBase_ModelWidget(theParent, theData, theParentId), isValidateBlocked(false)
+: ModuleBase_ModelWidget(theParent, theData, theParentId), isValidateBlocked(false),
+ myWorkshop(theWorkshop)
{
}
}
//********************************************************************
-bool ModuleBase_WidgetValidated::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
+bool ModuleBase_WidgetValidated::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate)
{
if (theValues.empty())
return false;
ModuleBase_ViewerPrs aValue = theValues.takeFirst();
bool isDone = false;
- if (isValidSelection(aValue)) {
+ if (!theToValidate || isValidInFilters(aValue)) {
isDone = setSelectionCustom(aValue);
// updateObject - to update/redisplay feature
// it is commented in order to perfom it outside the method
return isDone;
}
+//********************************************************************
+bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrs& thePrs)
+{
+ bool aValid = true;
+ Handle(SelectMgr_EntityOwner) anOwner = thePrs.owner();
+
+ // if an owern is null, the selection happens in the Object browser.
+ // creates a selection owner on the base of object shape and the object AIS object
+ if (anOwner.IsNull() && thePrs.owner().IsNull() && thePrs.object().get()) {
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+ if (aResult.get()) {
+ GeomShapePtr aShape = aResult->shape();
+
+ const TopoDS_Shape aTDShape = aShape->impl<TopoDS_Shape>();
+ Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs);
+ anOwner = new StdSelect_BRepOwner(aTDShape, anIO);
+ }
+ }
+ // finds
+ if (!anOwner.IsNull()) {
+ const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters();
+ SelectMgr_ListIteratorOfListOfFilter anIt(aFilters);
+ for (; anIt.More() && aValid; anIt.Next()) {
+ Handle(SelectMgr_Filter) aFilter = anIt.Value();
+ //if (aFilter == myWorkshop->validatorFilter())
+ // continue;
+ aValid = aFilter->IsOk(anOwner);
+ }
+ }
+ // removes created owner
+ if (!anOwner.IsNull() && anOwner != thePrs.owner())
+ anOwner.Nullify();
+ return aValid;
+}
+
//********************************************************************
bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& theValue)
{
return aValid;
}
-void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
- const bool toActivate)
+void ModuleBase_WidgetValidated::activateFilters(const bool toActivate)
{
- ModuleBase_IViewer* aViewer = theWorkshop->viewer();
+ ModuleBase_IViewer* aViewer = myWorkshop->viewer();
- Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
+ Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
if (toActivate)
aViewer->addSelectionFilter(aSelFilter);
else {
/// \param theData the widget configuation. The attribute of the model widget is obtained from
/// \param theParentId is Id of a parent of the current attribute
ModuleBase_WidgetValidated(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId);
virtual ~ModuleBase_WidgetValidated();
+ /// Checks whether all active viewer filters validate the presentation
+ /// \param theWorkshop an active workshop
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ bool isValidInFilters(const ModuleBase_ViewerPrs& thePrs);
+
/// Checks all widget validator if the owner is valid
/// \param theValue a selected presentation in the view
/// \return a boolean value
/// The method is called by the current operation to process the operation preselection.
/// It is redefined to check the value validity and if it is, fill the attribute with by value
/// \param theValues the wrapped selection values
- virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
-
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate);
protected:
/// Creates a backup of the current values of the attribute
/// It should be realized in the specific widget because of different
/// It obtains selection filters from the workshop and activates them in the active viewer
/// \param theWorkshop an active workshop
/// \param toActivate a flag about activation or deactivation the filters
- virtual void activateFilters(ModuleBase_IWorkshop* theWorkshop, const bool toActivate);
+ virtual void activateFilters(const bool toActivate);
/// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
/// \param theValue a viewer presentation
// Removes all presentations from internal maps.
void clearValidState();
+protected:
+ ModuleBase_IWorkshop* myWorkshop; /// Reference to workshop
+
private:
QList<ModuleBase_ViewerPrs> myValidPrs;
QList<ModuleBase_ViewerPrs> myInvalidPrs;
XGUI_Workshop* aXUIWorkshop = aConnector->workshop();
ModuleBase_ModelWidget* aWgt = NULL;
if (theType == "sketch-start-label") {
- PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent,
+ PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, aWorkshop,
theWidgetApi, theParentId, mySketchMgr->isConstraintsShown());
- aLabelWgt->setWorkshop(aXUIWorkshop);
connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr<GeomAPI_Pln>&)),
mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)),
delete myExternalObjectMgr;
}
-bool PartSet_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
+bool PartSet_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate)
{
- bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues);
+ bool aSucceed = ModuleBase_WidgetMultiSelector::setSelection(theValues, theToValidate);
if (aSucceed) {
// TODO(nds): unite with externalObject(), remove parameters
//myFeature->execute();
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
/// \param theValues the wrapped selection values
- virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate);
protected:
/// Checks the widget validity. By default, it returns true.
{
}
-bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
+bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate)
{
if (theValues.empty())
return false;
/// Set the given wrapped value to the current widget
/// This value should be processed in the widget according to the needs
/// \param theValues the wrapped widget values
- virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate);
virtual bool restoreValue();
PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
+ ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
const std::string& theParentId,
bool toShowConstraints)
- : ModuleBase_WidgetValidated(theParent, theData, theParentId),
- myPreviewDisplayed(false),
- myWorkshop(NULL)
+: ModuleBase_WidgetValidated(theParent, theWorkshop, theData, theParentId),
+ myPreviewDisplayed(false)
{
myText = QString::fromStdString(theData->getProperty("title"));
myLabel = new QLabel("", theParent);
erasePreviewPlanes();
}
-bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrs>& theValues)
+bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate)
{
// do not use the given selection if the plane of the sketch has been already set.
// If this check is absent, a selected plane in the viewer can be set in the sketch
if (plane().get())
return true;
- return ModuleBase_WidgetValidated::setSelection(theValues);
+ return ModuleBase_WidgetValidated::setSelection(theValues, theToValidate);
}
QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
void PartSet_WidgetSketchLabel::onSelectionChanged()
{
- QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selector()->selection()->getSelected(
+ QList<ModuleBase_ViewerPrs> aSelected = myWorkshop->selection()->getSelected(
ModuleBase_ISelection::AllControls);
if (aSelected.empty())
return;
ModuleBase_ViewerPrs aPrs = aSelected.first();
- bool isDone = ModuleBase_WidgetValidated::setSelection(aSelected);
+ bool isDone = ModuleBase_WidgetValidated::setSelection(aSelected, true);
if (!isDone)
return;
// 5. Clear text in the label
myLabel->setText("");
myLabel->setToolTip("");
- disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()),
+ disconnect(workshop()->selector(), SIGNAL(selectionChanged()),
this, SLOT(onSelectionChanged()));
// 6. deactivate face selection filter
- activateFilters(myWorkshop->module()->workshop(), false);
+ activateFilters(false);
// 7. Clear selection mode and define sketching mode
- //XGUI_Displayer* aDisp = myWorkshop->displayer();
+ //XGUI_Displayer* aDisp = workshop()->displayer();
//aDisp->closeLocalContexts();
emit planeSelected(plane());
// after the plane is selected in the sketch, the sketch selection should be activated
activateSelection(true);
// 8. Update sketcher actions
- XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr();
+ XGUI_ActionsMgr* anActMgr = workshop()->actionsMgr();
anActMgr->update();
myWorkshop->viewer()->update();
}
}
bool aBodyIsVisualized = false;
- XGUI_Displayer* aDisp = myWorkshop->displayer();
+ XGUI_Displayer* aDisp = workshop()->displayer();
QObjectPtrList aDisplayed = aDisp->displayedObjects();
foreach (ObjectPtr anObj, aDisplayed) {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
myLabel->setText(myText);
myLabel->setToolTip(myTooltip);
- connect(myWorkshop->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
- activateFilters(myWorkshop->module()->workshop(), true);
+ connect(workshop()->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+ activateFilters(true);
aDisp->updateViewer();
}
erasePreviewPlanes();
activateSelection(false);
- activateFilters(myWorkshop->module()->workshop(), false);
+ activateFilters(false);
}
void PartSet_WidgetSketchLabel::activateSelection(bool toActivate)
QIntList aModes;
std::shared_ptr<GeomAPI_Pln> aPlane = plane();
if (aPlane.get()) {
- myWorkshop->moduleConnector()->module()->activeSelectionModes(aModes);
+ myWorkshop->module()->activeSelectionModes(aModes);
}
else {
aModes << TopAbs_FACE;
}
- myWorkshop->moduleConnector()->activateSubShapesSelection(aModes);
+ myWorkshop->activateSubShapesSelection(aModes);
} else {
- myWorkshop->moduleConnector()->deactivateSubShapesSelection();
+ myWorkshop->deactivateSubShapesSelection();
}
}
void PartSet_WidgetSketchLabel::erasePreviewPlanes()
{
if (myPreviewDisplayed) {
- XGUI_Displayer* aDisp = myWorkshop->displayer();
+ XGUI_Displayer* aDisp = workshop()->displayer();
aDisp->eraseAIS(myYZPlane, false);
aDisp->eraseAIS(myXZPlane, false);
aDisp->eraseAIS(myXYPlane, false);
myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG);
myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB);
}
- XGUI_Displayer* aDisp = myWorkshop->displayer();
+ XGUI_Displayer* aDisp = workshop()->displayer();
aDisp->displayAIS(myYZPlane, false);
aDisp->displayAIS(myXZPlane, false);
aDisp->displayAIS(myXYPlane, false);
myShowConstraints->setChecked(theOn);
emit showConstraintToggled(theOn);
}
+
+XGUI_Workshop* PartSet_WidgetSketchLabel::workshop() const
+{
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ return aConnector->workshop();
+}
/// \param theParent the parent object
/// \param theData the widget configuation. The attribute of the model widget is obtained from
/// \param theParentId is Id of a parent of the current attribute
- PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData,
+ PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop,
+ const Config_WidgetAPI* theData,
const std::string& theParentId, bool toShowConstraints);
virtual ~PartSet_WidgetSketchLabel();
/// The method is called by the current operation to process the operation preselection.
/// It is redefined to do nothing if the plane of the sketch has been already set.
/// \param theValues the wrapped selection values
- virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues);
+ virtual bool setSelection(QList<ModuleBase_ViewerPrs>& theValues,
+ const bool theToValidate);
virtual bool restoreValue()
{
/// The methiod called when widget is deactivated
virtual void deactivate();
- /// Returns pointer to workshop
- XGUI_Workshop* workshop() const { return myWorkshop; }
-
- /// Set pointer to workshop
- /// \param theWork a pointer to workshop
- void setWorkshop(XGUI_Workshop* theWork) { myWorkshop = theWork; }
-
/// Returns sketcher plane
std::shared_ptr<GeomAPI_Pln> plane() const;
std::shared_ptr<GeomAPI_Dir> theNorm,
const int theRGB[3]);
+ //! Returns workshop
+ XGUI_Workshop* workshop() const;
+
/// Set sketch plane by shape
/// \param theShape a planar face
std::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
QString myText;
QString myTooltip;
- XGUI_Workshop* myWorkshop;
-
AISObjectPtr myYZPlane;
AISObjectPtr myXZPlane;
AISObjectPtr myXYPlane;