Separation of AIS objects activation in the local selection from the feature display/redisplay
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
if (myModule->workshop()->displayer()->IsVisible(aFeature) ||
- aType == EVENT_FEATURE_CREATED)
- myModule->visualizePreview(aFeature, true);
+ aType == EVENT_FEATURE_CREATED) {
+ myModule->visualizePreview(aFeature, true, false);
+ if (aType == EVENT_FEATURE_CREATED)
+ myModule->activateFeature(aFeature, true);
+ myModule->workshop()->displayer()->UpdateViewer();
+ }
}
if (aType == EVENT_FEATURE_DELETED)
{
aViewer->enableMultiselection(theEnabled);
}
+void PartSet_Module::onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop)
+{
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ aDisplayer->StopSelection(theFeatures, isStop);
+
+}
+
void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature,
int theMode)
{
bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Abort;
- visualizePreview(theFeature, isDisplay);
+ visualizePreview(theFeature, isDisplay, false);
+
+ if (theMode == FM_Activation || theMode == FM_Deactivation)
+ activateFeature(theFeature, true);
}
ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId)
connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
this, SLOT(onMultiSelectionEnabled(bool)));
+ connect(aPreviewOp, SIGNAL(multiSelectionEnabled(bool)),
+ this, SLOT(onMultiSelectionEnabled(bool)));
+ connect(aPreviewOp, SIGNAL(stopSelection(const std::list<XGUI_ViewerPrs>&, const bool)),
+ this, SLOT(onStopSelection(const std::list<XGUI_ViewerPrs>&, const bool)));
+
PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
if (aSketchOp) {
connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
Events_Loop::loop()->send(aMessage);
}
-void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay)
+void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+ const bool isUpdateViewer)
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
if (!anOperation)
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
- aDisplayer->RedisplayInLocalContext(theFeature,
- aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
- aPreviewOp->getSelectionModes(theFeature));
+ aDisplayer->Redisplay(theFeature,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
}
- else {
- //aDisplayer->CloseLocalContexts(false);
- aDisplayer->Erase(anOperation->feature());
+ else
+ aDisplayer->Erase(anOperation->feature(), false);
+
+ if (isUpdateViewer)
+ aDisplayer->UpdateViewer();
+}
+
+void PartSet_Module::activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const bool isUpdateViewer)
+{
+ ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ aDisplayer->ActivateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+ isUpdateViewer);
}
}
for (; anIt != aLast; anIt++) {
boost::shared_ptr<ModelAPI_Feature> aFeature = (*anIt).first;
boost::shared_ptr<GeomAPI_Shape> aPreview = (*anIt).second;
- aDisplayer->RedisplayInLocalContext(aFeature,
- aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
- aModes, false);
+ aDisplayer->Redisplay(aFeature,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+ aDisplayer->ActivateInLocalContext(aFeature, aModes, false);
}
aDisplayer->UpdateViewer();
}
class QKeyEvent;
class PartSet_Listener;
class ModelAPI_Feature;
+class XGUI_ViewerPrs;
class PARTSET_EXPORT PartSet_Module: public QObject, public XGUI_Module
{
virtual void launchOperation(const QString& theCmdId);
/// Displays or erase the current operation preview, if it has it.
- /// \param theF
+ /// \param theFeature the feature instance to be displayed
/// \param isDisplay the state whether the presentation should be displayed or erased
- void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay);
+ /// \param isUpdateViewer the flag whether the viewer should be updated
+ void visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay,
+ const bool isUpdateViewer = true);
+
+ /// Activates the feature in the displayer
+ /// \param theFeature the feature instance to be displayed
+ /// \param isUpdateViewer the flag whether the viewer should be updated
+ void activateFeature(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const bool isUpdateViewer);
/// Updates current operation preview, if it has it.
/// \param theCmdId the operation name
/// \param theEnabled the enabled state
void onMultiSelectionEnabled(bool theEnabled);
+ /// SLOT, to stop or start selection for the features
+ /// \param theFeatures a list of features to be disabled
+ /// \param theToStop the boolean state whether it it stopped or non stopped
+ void onStopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop);
+
/// SLOT, to visualize the feature in another local context mode
/// \param theFeature the feature to be put in another local context mode
/// \param theMode the mode appeared on the feature
std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
std::list<int> aModes;
- aModes.push_back(TopAbs_VERTEX);
- aModes.push_back(TopAbs_EDGE);
+ aModes.push_back(-1);
return aModes;
+ //return PartSet_OperationSketchBase::getSelectionModes(theFeature);
}
void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
{
// do nothing in order to do not create a new feature
emit multiSelectionEnabled(false);
+ emit stopSelection(myFeatures, true);
myCurPoint.clear();
}
void PartSet_OperationEditLine::stopOperation()
{
emit multiSelectionEnabled(true);
+ emit stopSelection(myFeatures, false);
myFeatures.clear();
}
std::list<int> aModes;
if (!myIsEditMode)
aModes.push_back(TopAbs_FACE);
- else {
- aModes.push_back(TopAbs_VERTEX);
- aModes.push_back(TopAbs_EDGE);
- }
+ else
+ aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
return aModes;
}
return std::map<boost::shared_ptr<ModelAPI_Feature>, boost::shared_ptr<GeomAPI_Shape> >();
}
+std::list<int> PartSet_OperationSketchBase::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
+{
+ std::list<int> aModes;
+ aModes.push_back(TopAbs_VERTEX);
+ aModes.push_back(TopAbs_EDGE);
+ return aModes;
+}
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature()
{
boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature();
/// \param theEnabled the boolean state
void multiSelectionEnabled(bool theEnabled);
+ /// signal to enable/disable selection in the viewer
+ /// \param theFeatures a list of features to be disabled
+ /// \param theToStop the boolean state whether it it stopped or non stopped
+ void stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool theToStop);
+
/// signal to enable/disable usual selection in the viewer
/// \param theEnabled the boolean state
void selectionEnabled(bool theEnabled);
{
std::list<int> aModes;
if (theFeature != feature())
- {
- aModes.push_back(TopAbs_VERTEX);
- aModes.push_back(TopAbs_EDGE);
- }
+ aModes = PartSet_OperationSketchBase::getSelectionModes(theFeature);
return aModes;
}
aContext->UpdateCurrentViewer();
}
-void XGUI_Displayer::RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape,
- const std::list<int>& theModes, const bool isUpdateViewer)
+void XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
// Open local context if there is no one
if (!aContext->HasOpenedContext()) {
aContext->ClearCurrents(false);
- aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
- true/*allow shape decomposition*/);
+ aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
}
// display or redisplay presentation
Handle(AIS_Shape) anAIS;
// If there was a problem here, try the first solution with close/open local context.
anAIS->Set(theShape);
anAIS->Redisplay();
- if (aContext->IsSelected(anAIS)) {
+ /*if (aContext->IsSelected(anAIS)) {
aContext->AddOrRemoveSelected(anAIS, false);
aContext->AddOrRemoveSelected(anAIS, false);
//aContext->SetSelected(anAIS, false);
- }
+ }*/
}
}
else {
myFeature2AISObjectMap[theFeature] = anAIS;
aContext->Display(anAIS, false);
}
+}
+
+void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<int>& theModes, const bool isUpdateViewer)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ // Open local context if there is no one
+ if (!aContext->HasOpenedContext()) {
+ aContext->ClearCurrents(false);
+ aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+ }
+ // display or redisplay presentation
+ Handle(AIS_Shape) anAIS;
+ if (IsVisible(theFeature))
+ anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[theFeature]);
+ //if (!anAIS.IsNull())
+ // return;
+
// Activate selection of objects from prs
if (!anAIS.IsNull()) {
- aContext->Load(anAIS, -1, true/*allow decomposition*/);
+ aContext->Load(anAIS, -1, true/*allow decomposition*/);
+ aContext->Deactivate(anAIS);
+
std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
+ QString aDebugStr = QString(featureInfo(theFeature).c_str()) + QString("; modes: ");
for (; anIt != aLast; anIt++)
{
aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
- }
+ aDebugStr += QString("%1").arg(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt)) + QString(", ");
+ }
+ /*if (theModes.empty()) {
+ aContext->Deactivate(anAIS);
+ aContext->Activate(anAIS, -1);
+ aContext->ClearSelected();
+ aDebugStr += " deactivated";
+ QColor aColor(Qt::white);
+ anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+ }*/
+ qDebug(aDebugStr.toStdString().c_str());
}
if (isUpdateViewer)
aContext->UpdateCurrentViewer();
}
+void XGUI_Displayer::StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop)
+{
+ return;
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+
+ Handle(AIS_Shape) anAIS;
+ std::list<XGUI_ViewerPrs>::const_iterator anIt = theFeatures.begin(), aLast = theFeatures.end();
+ boost::shared_ptr<ModelAPI_Feature> aFeature;
+ for (; anIt != aLast; anIt++) {
+ aFeature = (*anIt).feature();
+ if (IsVisible(aFeature))
+ anAIS = Handle(AIS_Shape)::DownCast(myFeature2AISObjectMap[aFeature]);
+ if (anAIS.IsNull())
+ continue;
+
+ if (isStop) {
+ aContext->Deactivate(anAIS);
+ aContext->Activate(anAIS, -1);
+ aContext->ClearSelected();
+
+ //aDebugStr += " deactivated";
+ QColor aColor(Qt::white);
+ anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+ }
+ else {
+ //QColor aColor(Qt::red);
+ //anAIS->SetColor(Quantity_Color(aColor.red()/255., aColor.green()/255., aColor.blue()/255., Quantity_TOC_RGB));
+ }
+ }
+}
+
void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) ic = AISContext();
/// \param theShape a shape
/// \param theMode a local selection mode
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
- void RedisplayInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
- const TopoDS_Shape& theShape,
- const std::list<int>& theMode, const bool isUpdateViewer = true);
+ void Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const TopoDS_Shape& theShape, const bool isUpdateViewer = true);
+
+ /// Display the shape and activate selection of sub-shapes
+ /// \param theFeature a feature instance
+ /// \param theShape a shape
+ /// \param theMode a list of local selection modes
+ /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+ void ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
+ const std::list<int>& theModes, const bool isUpdateViewer = true);
+
+ /// Stop the current selection and color the given features to the selection color
+ /// \param theFeatures a list of features to be disabled
+ /// \param theToStop the boolean state whether it it stopped or non stopped
+ void StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop);
/// Erase the feature and a shape.
/// \param theFeature a feature instance
FeatureToAISMap myFeature2AISObjectMap;
};
+
#endif
{
std::ostringstream aStream;
if (theFeature)
- aStream << theFeature.get();
+ aStream << theFeature.get() << " " << theFeature->getKind();
return QString(aStream.str().c_str()).toStdString();
}