Correct displayer to cash in an internal map one AIS for one feature (there was a vector of AIS).
Reuse AIS for the same feature in Redisplay.
#include <PartSet_Module.h>
+#include <XGUI_Displayer.h>
+
#include <Events_Loop.h>
#include <Model_Events.h>
{
const Model_FeatureUpdatedMessage* aUpdMsg = dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
boost::shared_ptr<ModelAPI_Feature> aFeature = aUpdMsg->feature();
- myModule->visualizePreview(aFeature, true);
+ if (myModule->workshop()->displayer()->IsVisible(aFeature))
+ myModule->visualizePreview(aFeature, true);
}
}
XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
- connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
this, SLOT(onOperationStopped(ModuleBase_Operation*)));
{
}
+XGUI_Workshop* PartSet_Module::workshop() const
+{
+ return myWorkshop;
+}
+
void PartSet_Module::createFeatures()
{
Config_ModuleReader aXMLReader = Config_ModuleReader();
sendOperation(anOperation);
}
-void PartSet_Module::onOperationStarted()
-{
- ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-
- PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp) {
- visualizePreview(aPreviewOp->feature(), true);
-
- connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)),
- this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)));
- connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)),
- this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
-
- PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
- if (aSketchOp) {
- connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
- this, SLOT(onPlaneSelected(double, double, double)));
- }
- }
-}
-
void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
{
if (!theOperation)
return;
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(theOperation);
- //if (aPreviewOp)
- // visualizePreview(false);
}
void PartSet_Module::onSelectionChanged()
anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
+ // connect
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ if (aPreviewOp) {
+ connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)),
+ this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>, int)));
+ connect(aPreviewOp, SIGNAL(launchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)),
+ this, SLOT(onLaunchOperation(std::string, boost::shared_ptr<ModelAPI_Feature>)));
+
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
+ this, SLOT(onPlaneSelected(double, double, double)));
+ }
+ }
+
return anOperation;
}
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
- if (aPreview) {
- aDisplayer->RedisplayInLocalContext(theFeature, aPreview->impl<TopoDS_Shape>(),
- aPreviewOp->getSelectionModes(theFeature));
- }
+ aDisplayer->RedisplayInLocalContext(theFeature,
+ aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(),
+ aPreviewOp->getSelectionModes(theFeature));
}
else {
//aDisplayer->CloseLocalContexts(false);
PartSet_Module(XGUI_Workshop* theWshop);
virtual ~PartSet_Module();
+ /// Returns the module workshop
+ /// \returns a workshop instance
+ XGUI_Workshop* workshop() const;
+
virtual void createFeatures();
virtual void featureCreated(XGUI_Command* theFeature);
virtual QStringList nestedFeatures(QString theFeature);
public slots:
void onFeatureTriggered();
- /// SLOT, that is called after the operation is started. Perform some specific for module
- /// actions, e.g. connect the sketch feature to the viewer selection and show the sketch preview.
- void onOperationStarted();
/// SLOT, that is called after the operation is stopped. Disconnect the sketch feature
/// from the viewer selection and show the sketch preview.
void onOperationStopped(ModuleBase_Operation* theOperation);
PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
QObject* theParent)
-: PartSet_OperationSketchBase(theId, theParent)
+: PartSet_OperationSketchBase(theId, theParent), myIsEditMode(false)
{
}
std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
std::list<int> aModes;
- if (!isEditMode())
+ if (!myIsEditMode)
aModes.push_back(TopAbs_FACE);
return aModes;
}
void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
const TopoDS_Shape& theShape)
{
- if (!isEditMode()) {
+ if (!myIsEditMode) {
setSketchPlane(theShape);
- setEditMode(true);
+ myIsEditMode = true;
}
else if (theFeature)
emit launchOperation("EditLine", theFeature);
/// Set the plane to the current sketch
/// \param theShape the shape
void setSketchPlane(const TopoDS_Shape& theShape);
+
+private:
+ bool myIsEditMode; /// the edit mode of this operation
};
#endif
QObject* theParent)
: ModuleBase_Operation(theId, theParent)
{
- setEditMode(false);
}
PartSet_OperationSketchBase::~PartSet_OperationSketchBase()
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
return aFeature->preview();
}
+
+boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature()
+{
+ boost::shared_ptr<ModelAPI_Feature> aFeature = ModuleBase_Operation::createFeature();
+ emit featureConstructed(aFeature, FM_Activation);
+ return aFeature;
+}
/// theFeature the operation argument
void launchOperation(std::string theName, boost::shared_ptr<ModelAPI_Feature> theFeature);
-public:
- /// temporary code to provide edition mode
- void setEditMode(const bool isEditMode) { myIsEditMode = isEditMode; };
protected:
- bool isEditMode() const { return myIsEditMode; }
-private:
- bool myIsEditMode;
+ /// Creates an operation new feature
+ /// In addition to the default realization it appends the created line feature to
+ /// the sketch feature
+ /// \returns the created feature
+ virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
};
#endif
std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const
{
std::list<int> aModes;
- if (theFeature != feature())
+ if (theFeature != feature()) {
aModes.push_back(TopAbs_VERTEX);
+ aModes.push_back(TopAbs_EDGE);
+ }
return aModes;
}
boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
{
- boost::shared_ptr<ModelAPI_Feature> aNewFeature = PartSet_OperationSketchBase::createFeature();
+ boost::shared_ptr<ModelAPI_Feature> aNewFeature = ModuleBase_Operation::createFeature();
if (mySketch) {
boost::shared_ptr<SketchPlugin_Feature> aFeature =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(mySketch);
aFeature->addSub(aNewFeature);
}
- //emit featureConstructed(aNewFeature, FM_Activation);
+ emit featureConstructed(aNewFeature, FM_Activation);
return aNewFeature;
}
Handle(AIS_InteractiveContext) aContext = AISContext();
Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
- std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
- if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
- aDispAIS = myFeature2AISObjectMap[theFeature];
- }
- aDispAIS.push_back(anAIS);
- myFeature2AISObjectMap[theFeature] = aDispAIS;
+ myFeature2AISObjectMap[theFeature] = anAIS;
aContext->Display(anAIS, Standard_False);
-
if (isUpdateViewer)
aContext->UpdateCurrentViewer();
}
aFLast = myFeature2AISObjectMap.end();
for (; aFIt != aFLast && !aFeature; aFIt++)
{
- std::vector<Handle(AIS_InteractiveObject)> aDispAIS = (*aFIt).second;
- std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
- aLast = aDispAIS.end();
- Handle(AIS_InteractiveContext) aContext = AISContext();
- for (; anIt != aLast && !aFeature; anIt++) {
- Handle(AIS_InteractiveObject) anAIS = *anIt;
- Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
- if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) {
- aFeature = (*aFIt).first;
- }
+ Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
+ Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+ if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) {
+ aFeature = (*aFIt).first;
}
}
-
return aFeature;
}
if (myFeature2AISObjectMap.find(theFeature) == myFeature2AISObjectMap.end())
return;
- std::vector<Handle(AIS_InteractiveObject)> aDispAIS = myFeature2AISObjectMap[theFeature];
- std::vector<Handle(AIS_InteractiveObject)>::const_iterator anIt = aDispAIS.begin(),
- aLast = aDispAIS.end();
Handle(AIS_InteractiveContext) aContext = AISContext();
- for (; anIt != aLast; anIt++) {
- Handle(AIS_InteractiveObject) anAIS = *anIt;
- Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
- if (anAISShape.IsNull())
- continue;
- aContext->Erase(anAISShape);
+ Handle(AIS_InteractiveObject) anAIS = myFeature2AISObjectMap[theFeature];
+ Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+ if (!anAISShape.IsNull())
+ {
+ aContext->Erase(anAISShape);
}
myFeature2AISObjectMap.erase(theFeature);
const std::list<int>& theModes, const bool isUpdateViewer)
{
Handle(AIS_InteractiveContext) aContext = AISContext();
-
- if (IsVisible(theFeature)) {
- Erase(theFeature, false);
- }
-
- Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
- std::vector<Handle(AIS_InteractiveObject)> aDispAIS;
- if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end()) {
- aDispAIS = myFeature2AISObjectMap[theFeature];
- }
- aDispAIS.push_back(anAIS);
- myFeature2AISObjectMap[theFeature] = aDispAIS;
-
- Handle(AIS_InteractiveContext) ic = AISContext();
-
// Open local context if there is no one
- if (!ic->HasOpenedContext()) {
- ic->ClearCurrents(false);
- ic->OpenLocalContext(false/*use displayed objects*/, /*true*/false/*use displayed objects*/,
+ if (!aContext->HasOpenedContext()) {
+ aContext->ClearCurrents(false);
+ aContext->OpenLocalContext(false/*use displayed objects*/, /*true*/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()) {
+ anAIS->Set(theShape);
+ anAIS->Redisplay();
+ }
+ }
+ else {
+ anAIS = new AIS_Shape(theShape);
+ myFeature2AISObjectMap[theFeature] = anAIS;
+ aContext->Display(anAIS, false);
+ }
// Activate selection of objects from prs
if (!anAIS.IsNull()) {
- if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) {
- ic->Display(anAIS, false);
- ic->Load(anAIS, -1, true/*allow decomposition*/);
- std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
- for (; anIt != aLast; anIt++)
- ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
+ aContext->Load(anAIS, -1, true/*allow decomposition*/);
+ std::list<int>::const_iterator anIt = theModes.begin(), aLast = theModes.end();
+ for (; anIt != aLast; anIt++)
+ {
+ aContext->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)*anIt));
}
}
+
if (isUpdateViewer)
- ic->UpdateCurrentViewer();
+ aContext->UpdateCurrentViewer();
}
void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
protected:
XGUI_Workshop* myWorkshop;
- typedef std::map<boost::shared_ptr<ModelAPI_Feature>, std::vector<Handle(AIS_InteractiveObject)> > FeatureToAISMap;
+ typedef std::map<boost::shared_ptr<ModelAPI_Feature>, Handle(AIS_InteractiveObject) > FeatureToAISMap;
FeatureToAISMap myFeature2AISObjectMap;
};