double aDist = aDistAttr->value();
GeomShapePtr aShape = aFaceAttr->value();
+ if (!aShape.get()) {
+ aShape = aFaceAttr->context()->shape();
+ }
+
if (aShape.get() != NULL) {
std::shared_ptr<GeomAPI_Pln> aPln = GeomAlgoAPI_FaceBuilder::plane(aShape);
std::shared_ptr<GeomAPI_Pnt> aOrig = aPln->location();
AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
(theAttribute);
std::shared_ptr<GeomAPI_Shape> aGeomShape = aSelectionAttr->value();
+ if (!aGeomShape.get()) {
+ // if the shape is empty, apply the validator to the shape of result
+ aGeomShape = aSelectionAttr->context()->shape();
+ }
// it is necessary to check whether the shape is face in order to set in selection a value
// with any type and check the type in this validator
// It is realized to select any object in OB and filter it in this validator (sketch plane)
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
/*
* ModuleBase_WidgetMultiSelector.cpp
#include <memory>
#include <string>
+//#define DEBUG_SHAPE_VALIDATION_PREVIOUS
+
ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
const Config_WidgetAPI* theData,
}
//********************************************************************
-bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+bool ModuleBase_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
- TopoDS_Shape aShape = thePrs.shape();
- if (!acceptSubShape(aShape))
- return false;
-
- ResultPtr aResult;
- if (!thePrs.owner().IsNull()) {
- ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner());
- aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- }
+#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
+ return true;
+#endif
+ GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
+ // if there is no selected shape, the method returns true
+ bool aValid;
+ if (!aShape.get())
+ aValid = true;
else {
- aResult = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs.object());
+ // Check that the selection corresponds to selection type
+ TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
+ aValid = acceptSubShape(aTopoShape);
}
+ if (aValid) {
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+
+ if (myFeature) {
+ // We can not select a result of our feature
+ const std::list<ResultPtr>& aResList = myFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ bool isSkipSelf = false;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+ if ((*aIt) == aResult) {
+ isSkipSelf = true;
+ break;
+ }
+ }
+ if(isSkipSelf)
+ aValid = false;
+ }
+
+ }
+ return aValid;
+}
+
+//********************************************************************
+bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+ //TopoDS_Shape aShape = thePrs.shape();
+ //if (!acceptSubShape(aShape))
+ // return false;
+
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+ /*
if (myFeature) {
// We can not select a result of our feature
const std::list<ResultPtr>& aResList = myFeature->results();
}
if(isSkipSelf)
return false;
- }
+ }*/
// if the result has the similar shap as the parameter shape, just the context is set to the
// selection list attribute.
AttributeSelectionListPtr aSelectionListAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
- const TopoDS_Shape& aTDSShape = thePrs.shape();
+ /*const TopoDS_Shape& aTDSShape = thePrs.shape();
// if only result is selected, an empty shape is set to the model
if (aTDSShape.IsNull()) {
aSelectionListAttr->append(aResult, GeomShapePtr());
aSelectionListAttr->append(aResult, GeomShapePtr());
else
aSelectionListAttr->append(aResult, aShape);
- }
+ }*/
+ GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
+ aSelectionListAttr->append(aResult, aShape);
+
return true;
}
return result;
}
-//********************************************************************
-bool ModuleBase_WidgetMultiSelector::eventFilter(QObject* theObj, QEvent* theEvent)
-{
- //TODO: Remove maybe?
- return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
-}
-
//********************************************************************
void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged()
{
/// \return a control list
virtual QList<QWidget*> getControls() const;
- virtual bool eventFilter(QObject* , QEvent* );
-
/// The methiod called when widget is deactivated
virtual void deactivate();
/// \param thePosition an index in the list of values, the values should be get from the index
virtual bool setSelection(const QList<ModuleBase_ViewerPrs>& theValues, int& thePosition);
+ /// Checks the widget validity. By default, it returns true.
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
/// Fills the attribute with the value of the selected owner
/// \param theOwner a selected owner
virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
// File: ModuleBase_WidgetShapeSelector.h
// Created: 2 June 2014
#include <list>
#include <string>
+//#define DEBUG_SHAPE_VALIDATION_PREVIOUS
ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
theArguments.push_back(anArguments);
}
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
+{
+#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
+ return true;
+#endif
+
+ GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
+ bool aValid;
+ // if there is no selected shape, the method returns true
+ if (!aShape.get())
+ aValid = true;
+ else {
+ // Check that the selection corresponds to selection type
+ TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
+ aValid = acceptSubShape(aTopoShape);
+ }
+ return aValid;
+}
+
//********************************************************************
bool ModuleBase_WidgetShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs)
{
bool isDone = false;
+ ResultPtr aResult = myWorkshop->selection()->getResult(thePrs);
+
// It should be checked by corresponded validator
- ObjectPtr aObject = thePrs.object();
- ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
+ //ObjectPtr aObject = thePrs.object();
+ //ObjectPtr aCurrentObject = GeomValidators_Tools::getObject(myFeature->attribute(attributeID()));
/*
if ((!aCurrentObject) && (!aObject))
return false;*/
// It should be checked by corresponded validator
// Check that the selected object is result (others can not be accepted)
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
- if (!aRes)
- return false;
+ //ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObject);
+ //if (!aRes)
+ // return false;
/*if (myFeature) {
// We can not select a result of our feature
const std::list<std::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
if (!(aDoc == aMgr->activeDocument()) && !(aDoc == aMgr->moduleDocument()))
return false;*/
+#ifdef DEBUG_SHAPE_VALIDATION_PREVIOUS
// It should be checked by corresponded validator
// Check that the result has a shape
GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
aShape->setImpl(new TopoDS_Shape(thePrs.shape()));
}
+
// Check that the selection corresponds to selection type
TopoDS_Shape aTopoShape = aShape->impl<TopoDS_Shape>();
if (!acceptSubShape(aTopoShape))
return false;
+#else
+ // the difference is that the next method returns an empty shape if the result has the same shape
+ // to be checked for all cases and uncommented
+ GeomShapePtr aShape = myWorkshop->selection()->getShape(thePrs);
+#endif
- setObject(aObject, aShape);
+ setObject(aResult, aShape);
return true;
}
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
// File: ModuleBase_WidgetShapeSelector.h
// Created: 2 June 2014
/// \return a control list
virtual QList<QWidget*> getControls() const;
+ /// Checks the widget validity. By default, it returns true.
+ /// \param theValue a selected presentation in the view
+ /// \return a boolean value
+ virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
+
/// Fills the attribute with the value of the selected owner
/// \param theOwner a selected owner
virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
#include <XGUI_PropertyPanel.h>
#include <XGUI_ViewerProxy.h>
-#include <AppElements_MainWindow.h>
-
#include <ModuleBase_IViewer.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IViewWindow.h>