void PartSet_WidgetSketchCreator::activateCustom()
{
- if (isSelectionMode()) {
- ModuleBase_WidgetSelector::activateCustom();
+ //if (isSelectionMode()) {
+ // ModuleBase_WidgetSelector::activateCustom();
//connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
//setVisibleSelectionControl(true);
- }
+ //}
//else {
// setVisibleSelectionControl(false);
// emit focusOutWidget(this);
{
QList<ModuleBase_ViewerPrs> aSelected = getFilteredSelected();
- if (aSelected.size() == 1) { // plane or planar face of not sketch object
- startSketchOperation(aSelected.front());
+ if (startSketchOperation(aSelected)) {
+
}
- else if (aSelected.size() > 1) {
+ else {// if (aSelected.size() > 1) {
QList<ModuleBase_ViewerPrs>::const_iterator anIt = aSelected.begin(), aLast = aSelected.end();
- bool aProcessed;
+ bool aProcessed = false;
for (; anIt != aLast; anIt++) {
ModuleBase_ViewerPrs aValue = *anIt;
if (isValidInFilters(aValue))
- aProcessed = setSelectionCustom(aValue);
+ aProcessed = setSelectionCustom(aValue) || aProcessed;
}
if (aProcessed) {
emit valuesChanged();
}
}
}
-void PartSet_WidgetSketchCreator::onStarted()
+//void PartSet_WidgetSketchCreator::onStarted()
+//{
+// disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
+//}
+
+bool PartSet_WidgetSketchCreator::startSketchOperation(const QList<ModuleBase_ViewerPrs>& theValues)
{
- disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted()));
+ bool aSketchStarted = false;
- setVisibleSelectionControl(true);
-}
+ if (theValues.size() != 1)
+ return aSketchStarted;
-void PartSet_WidgetSketchCreator::startSketchOperation(const ModuleBase_ViewerPrs& theValue)
-{
+ ModuleBase_ViewerPrs aValue = theValues.front();
+ if (!PartSet_WidgetSketchLabel::canFillSketch(aValue))
+ return aSketchStarted;
+
+ aSketchStarted = true;
// Check that model already has bodies
/*XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
XGUI_Workshop* aWorkshop = aConnector->workshop();
FeaturePtr aPreviousCurrentFeature = aDoc->currentFeature(false);
FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
- PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(aSketch, theValue);
+ PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(aSketch, aValue);
aDoc->setCurrentFeature(aPreviousCurrentFeature, false);
ModuleBase_Operation* aOp = myModule->workshop()->currentOperation();
aOp->abort();
}*/
+ return aSketchStarted;
}
bool PartSet_WidgetSketchCreator::focusTo()
{
if (isSelectionMode()) {
+ setVisibleSelectionControl(true);
+
//CompositeFeaturePtr aCompFeature =
// std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
// if (aCompFeature->numberOfSubs() == 0)
// return ModuleBase_ModelWidget::focusTo();
- connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
+ //connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted()));
// we need to call activate here as the widget has no focus accepted controls
// if these controls are added here, activate will happens automatically after focusIn()
- activate();
+ ModuleBase_WidgetSelector::activateCustom();
return true;
}
else {
+ setVisibleSelectionControl(false);
+
connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*)));
SessionPtr aMgr = ModelAPI_Session::get();
// Open transaction that is general for the previous nested one: it will be closed on nested commit
return fillSketchPlaneBySelection(feature(), thePrs);
}
+#include <GeomAPI_Face.h>
+bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrs& thePrs)
+{
+ bool aCanFillSketch = true;
+ // avoid any selection on sketch object
+ ObjectPtr anObject = thePrs.object();
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get()) {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
+ if (aFeature->getKind() == SketchPlugin_Sketch::ID())
+ aCanFillSketch = false;
+ }
+ // check plane or planar face of any non-sketch object
+ if (aCanFillSketch) {
+ const TopoDS_Shape aShape = thePrs.shape();
+ if (aShape.ShapeType() == TopAbs_FACE) {
+ std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face());
+ aGeomFace->setImpl(new TopoDS_Shape(aShape));
+ aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
+ }
+ else
+ aCanFillSketch = false;
+ }
+ return aCanFillSketch;
+}
+
bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& theFeature,
const ModuleBase_ViewerPrs& thePrs)
{