-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+#include "PartSet_WidgetFeaturePointSelector.h"
+#include "PartSet_Tools.h"
+#include "PartSet_ExternalObjectsMgr.h"
+
#include <Config_WidgetAPI.h>
#include <Events_Loop.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IModule.h>
-#include "PartSet_WidgetFeaturePointSelector.h"
-#include "PartSet_Tools.h"
-
#include <SketchPlugin_Point.h>
#include <XGUI_Tools.h>
: ModuleBase_WidgetShapeSelector(theParent, theWorkshop, theData)
{
std::string anAttributes = theData->getProperty("selection_attributes");
- QStringList anAttributesList = QString(anAttributes.c_str()).split(' ', QString::SkipEmptyParts);
+ QStringList anAttributesList =
+ QString(anAttributes.c_str()).split(' ', QString::SkipEmptyParts);
myHasPreview = anAttributesList.size() >= 4;
myPreviewObjectAttribute = anAttributesList[2].toStdString();
myPreviewPointAttribute = anAttributesList[3].toStdString();
}
+ myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
+ theData->getProperty("can_create_external"), true);
}
PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector()
{
+ delete myExternalObjectMgr;
}
//********************************************************************
//return true;
}
-//********************************************************************
-void PartSet_WidgetFeaturePointSelector::updateSelectionModesAndFilters(bool toActivate)
-{
-#ifdef HIGHLIGHT_STAYS_PROBLEM
- Handle(AIS_InteractiveContext) aContext =
- XGUI_Tools::workshop(myWorkshop)->viewer()->AISContext();
- Quantity_Color aColor;
- Handle(Prs3d_Drawer) aHStyle = aContext->HighlightStyle();
- Handle(Prs3d_Drawer) aSStyle = aContext->SelectionStyle();
- if (toActivate) {
- std::vector<int> aColors;
- aColors = Config_PropManager::color("Visualization", "sketch_entity_color");
- aColor = Quantity_Color(aColors[0] / 255., aColors[1] / 255., aColors[2] / 255.,
- Quantity_TOC_RGB);
- myHighlightColor = aHStyle->Color();
- mySelectionColor = aSStyle->Color();
- }
- else {
- aColor = myHighlightColor;
- }
- aHStyle->SetColor(aColor);
- aContext->SetHighlightStyle(aHStyle);
-
- aSStyle->SetColor(aColor);
- aContext->SetSelectionStyle(aSStyle);
-
-#endif
-
- ModuleBase_WidgetShapeSelector::updateSelectionModesAndFilters(toActivate);
-}
-
//********************************************************************
void PartSet_WidgetFeaturePointSelector::activateCustom()
{
ModuleBase_ViewerPrsPtr aPrs = !aHighlighted.empty() ? aHighlighted.first()
: ModuleBase_ViewerPrsPtr();
- fillFeature(aPrs, theWindow, theEvent);
+ myPreviewPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch);
+ if (myHasPreview) {
+ if (aPrs.get() && aPrs->object().get())
+ myPreviewObject = aPrs->object();
+ else
+ myPreviewObject = ObjectPtr();
+ fillFeature();
+ updateObject(feature());
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
+ }
}
//********************************************************************
if (theEvent->button() != Qt::LeftButton)
return;
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ QList<ModuleBase_ViewerPrsPtr> aSelected =
+ aSelection->getSelected(ModuleBase_ISelection::Viewer);
+
+ ModuleBase_ViewerPrsPtr aPrs =
+ !aSelected.empty() ? aSelected.first() : ModuleBase_ViewerPrsPtr();
+ if (aPrs.get() && aPrs->object().get()) {
+ myPreviewObject = aSelection->getResult(aPrs);
+ GeomShapePtr aShape = aSelection->getShape(aPrs);
+ myExternalObjectMgr->getGeomSelection(aPrs, myPreviewObject, aShape,
+ myWorkshop, sketch(), true);
+ }
+ myPreviewPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch);
+
ObjectPtr aPreviewObject;
GeomPnt2dPtr aPreviewPoint;
if (myHasPreview) {
if (!aPreviewObject.get())
return;
+ // Do not use non-sketcher objects
+ if (!sketch()->isSub(aPreviewObject))
+ return;
+
// set parameters of preview into parameters of selection in the feature
std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
}
//********************************************************************
-bool PartSet_WidgetFeaturePointSelector::fillFeature(
- const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
- ModuleBase_IViewWindow* theWindow,
- QMouseEvent* theEvent)
+bool PartSet_WidgetFeaturePointSelector::fillFeature()
{
- bool aFilled = false;
- if (theSelectedPrs.get() && theSelectedPrs->object().get())
- myPreviewObject = theSelectedPrs->object();
- myPreviewPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch);
-
if (myHasPreview) {
std::shared_ptr<ModelAPI_AttributeReference> aRef =
std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
feature()->data()->attribute(myPreviewObjectAttribute));
aRef->setValue(myPreviewObject);
-
- std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- feature()->data()->attribute(myPreviewPointAttribute));
- anAttributePoint->setValue(myPreviewPoint);
+ if (myPreviewPoint.get()) {
+ std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ feature()->data()->attribute(myPreviewPointAttribute));
+ anAttributePoint->setValue(myPreviewPoint);
+ }
+ }
+ else {
+ // Do not use non-sketcher objects
+ if (!sketch()->isSub(myPreviewObject))
+ return false;
+
+ // set parameters of preview into parameters of selection in the feature
+ if (myPreviewPoint.get()) {
+ std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ feature()->data()->attribute(mySelectedPointAttribute));
+ aPointSelectedAttr->setValue(myPreviewPoint);
+ }
+ AttributeReferencePtr aRefSelectedAttr = feature()->reference(mySelectedObjectAttribute);
+ if (aRefSelectedAttr)
+ aRefSelectedAttr->setValue(myPreviewObject);
+ else {
+ AttributeRefAttrPtr aRefAttrSelectedAttr = feature()->refattr(mySelectedObjectAttribute);
+ if (aRefAttrSelectedAttr)
+ aRefAttrSelectedAttr->setObject(myPreviewObject);
+ }
}
// redisplay AIS presentation in viewer
#ifndef HIGHLIGHT_STAYS_PROBLEM
// an attempt to clear highlighted item in the viewer: but of OCCT
XGUI_Tools::workshop(myWorkshop)->displayer()->clearSelected(true);
#endif
- updateObject(feature());
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
-
- aFilled = true;
-
- return aFilled;
+ return true;
}
//********************************************************************
}
//********************************************************************
-bool PartSet_WidgetFeaturePointSelector::setSelection(
- QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
- const bool theToValidate)
+bool PartSet_WidgetFeaturePointSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
{
- // false is returned to do not emit focus out widget by selected sub-shape
- return false;
+ if (!thePrs.get() || !thePrs->object().get())
+ return false;
+
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ myPreviewObject = aSelection->getResult(thePrs);
+ GeomShapePtr aShape = aSelection->getShape(thePrs);
+ myExternalObjectMgr->getGeomSelection(thePrs, myPreviewObject, aShape, myWorkshop,
+ sketch(), true);
+ return fillFeature();
}
+//********************************************************************
void PartSet_WidgetFeaturePointSelector::setPreSelection(
- const std::shared_ptr<ModuleBase_ViewerPrs>& thePreSelected,
+ const ModuleBase_ViewerPrsPtr& thePreSelected,
ModuleBase_IViewWindow* theWnd,
QMouseEvent* theEvent)
{
// sub-segments in the viewer, secondly preselection of restart operation is processed by
// special reentrant message sent by the feature
}
+
+//********************************************************************
+void PartSet_WidgetFeaturePointSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
+ ObjectPtr& theObject, GeomShapePtr& theShape)
+{
+ ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
+
+ myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
+ myWorkshop, sketch(), myIsInValidate);
+ myPreviewObject = theObject;
+}
+
+//********************************************************************
+void PartSet_WidgetFeaturePointSelector::restoreAttributeValue(const AttributePtr& theAttribute,
+ const bool theValid)
+{
+ ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
+ myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
+ myPreviewObject = ObjectPtr();
+}