--- /dev/null
+// File: PartSet_TestOCC.h
+// Created: 28 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_TestOCC.h>
+
+#include <XGUI_Workshop.h>
+#include <XGUI_OperationMgr.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_ViewerPrs.h>
+#include <XGUI_ViewerProxy.h>
+#include <PartSet_OperationSketchLine.h>
+
+#include <ModelAPI_Feature.h>
+
+#include <SketchPlugin_Line.h>
+#include <ModelAPI_Document.h>
+
+static double myTestDelta;
+static boost::shared_ptr<ModelAPI_Feature> myTestFeature;
+
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_Shape.hxx>
+#include <V3d_View.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRep_Tool.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+
+void PartSet_TestOCC::testSelection(XGUI_Workshop* theWorkshop)
+{
+ if (!myTestFeature) {
+ PartSet_TestOCC::createTestLine(theWorkshop);
+ PartSet_TestOCC::moveMouse(theWorkshop->viewer()->AISContext(),
+ theWorkshop->viewer()->activeView());
+ PartSet_TestOCC::changeTestLine(theWorkshop);
+ }
+ Handle(AIS_InteractiveObject) anIO = theWorkshop->displayer()->GetAISObject(myTestFeature);
+ if (!anIO.IsNull()) {
+ theWorkshop->viewer()->AISContext()->MoveTo(0, 0, theWorkshop->viewer()->activeView());
+ theWorkshop->viewer()->AISContext()->Select(0, 0, 2500, 2500, theWorkshop->viewer()->activeView());
+ }
+}
+
+void PartSet_TestOCC::testSelection_OCC(Handle_AIS_InteractiveContext theContext,
+ Handle_V3d_View theView)
+{
+ // 1. Create shape
+ gp_Pnt aPnt1(100, 100, 0);
+ gp_Pnt aPnt2(150, 300, 0);
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2).Edge();
+
+ // 2. Display shape and activate it in the local context
+ Handle(AIS_Shape) anAIS = new AIS_Shape(anEdge);
+ if (!theContext->HasOpenedContext()) {
+ theContext->ClearCurrents(false);
+ theContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+ }
+ theContext->Display(anAIS, false);
+ theContext->Load(anAIS, -1, true/*allow decomposition*/);
+ theContext->Activate(anAIS, AIS_Shape::SelectionMode(TopAbs_VERTEX));
+ theContext->Activate(anAIS, AIS_Shape::SelectionMode(TopAbs_EDGE));
+
+ // 3. Change selection in the viewer
+ // emulate rectangle selection in the viewer
+ theContext->Select(0, 0, 2500, 2500, theView);
+
+ // 3. Change the shape of AIS presentation
+ gp_Pnt aPnt3(-100, -100, 0);
+ gp_Pnt aPnt4(200, 200, 0);
+ TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(aPnt3, aPnt4).Edge();
+ anAIS->Set(anEdge2);
+ anAIS->Redisplay(Standard_True);
+ theContext->RecomputeSelectionOnly(anAIS);
+
+ // 4. Check the current viewer selection
+ Handle(AIS_InteractiveContext) aContext = theContext;
+ bool isFirstLinePoint = false;
+ bool isShapeSelected = false;
+ for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
+ TopoDS_Shape aShape = aContext->SelectedShape();
+ if (aShape.ShapeType() == TopAbs_VERTEX) {
+ const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+ if (!aVertex.IsNull()) {
+ gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+ double aD_1 = aPoint.Distance(aPnt1);
+ double aD_2 = aPoint.Distance(aPnt2);
+ isFirstLinePoint = aD_1 < Precision::Confusion() || aD_2 < Precision::Confusion();
+ }
+ }
+ }
+ if (isFirstLinePoint)
+ std::cout << "Error: The point of the first line should not be selected." << std::endl;
+}
+
+void PartSet_TestOCC::testErase_OCC(Handle_AIS_InteractiveContext theContext,
+ Handle_V3d_View theView)
+{
+ // 1. Create shape
+ gp_Pnt aPnt1(100, 100, 0);
+ gp_Pnt aPnt2(150, 300, 0);
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(aPnt1, aPnt2).Edge();
+
+ // 2. Display shape and activate it in the local context
+ Handle(AIS_Shape) anAIS = new AIS_Shape(anEdge);
+ if (!theContext->HasOpenedContext()) {
+ theContext->ClearCurrents(false);
+ theContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/);
+ }
+ theContext->Display(anAIS, false);
+ theContext->Load(anAIS, -1, true/*allow decomposition*/);
+ theContext->Activate(anAIS, AIS_Shape::SelectionMode(TopAbs_VERTEX));
+ theContext->Activate(anAIS, AIS_Shape::SelectionMode(TopAbs_EDGE));
+
+ // 3. Change selection in the viewer
+ // emulate rectangle selection in the viewer
+ theContext->Select(0, 0, 2500, 2500, theView);
+
+ theContext->Erase(anAIS);
+}
+
+void PartSet_TestOCC::createTestLine(XGUI_Workshop* theWorkshop)
+{
+ myTestDelta = 80;
+
+ ModuleBase_Operation* anOperation = theWorkshop->operationMgr()->currentOperation();
+ PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+ boost::shared_ptr<ModelAPI_Feature> aSketch;
+
+ if (aPreviewOp) {
+ // create a line
+ boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
+ boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature(
+ PartSet_OperationSketchLine::Type().c_str());
+ if (aFeature) // TODO: generate an error if feature was not created
+ aFeature->execute();
+
+ boost::shared_ptr<SketchPlugin_Feature> aSketch =
+ boost::dynamic_pointer_cast<SketchPlugin_Feature>(aPreviewOp->sketch());
+ aSketch->addSub(aFeature);
+
+ PartSet_OperationSketchLine::setLinePoint(aFeature, 100, 100, LINE_ATTR_START);
+ PartSet_OperationSketchLine::setLinePoint(aFeature, 150, 300, LINE_ATTR_END);
+
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+
+ XGUI_Displayer* aDisplayer = theWorkshop->displayer();
+ aDisplayer->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), false);
+ std::list<int> aModes;
+ aModes.push_back(TopAbs_VERTEX);
+ aModes.push_back(TopAbs_EDGE);
+ aDisplayer->ActivateInLocalContext(aFeature, aModes, true);
+
+ // change the line
+ /*double aDelta = -200;
+ for (int i = 0; i < 20; i++) {
+ aDelta = aDelta - i*2;
+ PartSet_OperationSketchLine::setLinePoint(aFeature, 100+aDelta, 200+aDelta, LINE_ATTR_START);
+ PartSet_OperationSketchLine::setLinePoint(aFeature, 300+aDelta, 500+aDelta, LINE_ATTR_END);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+
+ theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+
+ int aVal = 90;
+ for (int j = 0; j < 10000000; j++)
+ aVal = aVal/aVal+aVal*2;
+ }*/
+ //std::list<int> aModes;
+ //aModes.clear();
+ //aModes.push_back(TopAbs_VERTEX);
+ //aModes.push_back(TopAbs_EDGE);
+ //aDisplayer->ActivateInLocalContext(aFeature, aModes, true);
+ myTestFeature = aFeature;
+
+ std::list<XGUI_ViewerPrs> aPrs;
+ aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape()));
+ aDisplayer->SetSelected(aPrs, true);
+ }
+}
+
+void PartSet_TestOCC::changeTestLine(XGUI_Workshop* theWorkshop)
+{
+ // change the line
+ if (!myTestFeature)
+ return;
+ boost::shared_ptr<ModelAPI_Feature> aFeature = myTestFeature;
+
+ myTestDelta = myTestDelta - 50;
+ double aDelta = myTestDelta;
+ PartSet_OperationSketchLine::setLinePoint(aFeature, -100/*aDelta*/, -100/*aDelta*/, LINE_ATTR_START);
+ PartSet_OperationSketchLine::setLinePoint(aFeature, 200/*aDelta*2*/, 200/*aDelta*2*/, LINE_ATTR_END);
+ boost::shared_ptr<GeomAPI_Shape> aPreview = PartSet_OperationSketchLine::preview(aFeature);
+
+ theWorkshop->displayer()->Redisplay(aFeature, aPreview ? aPreview->impl<TopoDS_Shape>() : TopoDS_Shape(), true);
+ //std::list<int> aModes;
+ //aModes.clear();
+ //aModes.push_back(TopAbs_VERTEX);
+ //aModes.push_back(TopAbs_EDGE);
+ //aDisplayer->ActivateInLocalContext(aFeature, aModes, true);
+
+ /*std::list<XGUI_ViewerPrs> aPrs;
+ aPrs.push_back(XGUI_ViewerPrs(myTestFeature, TopoDS_Shape()));
+ theWorkshop->displayer()->SetSelected(aPrs, true);*/
+
+ theWorkshop->displayer()->UpdateViewer();
+}
+
+void PartSet_TestOCC::moveMouse(Handle(AIS_InteractiveContext) theContext, Handle(V3d_View) theView)
+{
+ theContext->MoveTo(10, 10, theView);
+ theContext->Select();
+}
\ No newline at end of file
--- /dev/null
+// File: PartSet_TestOCC.h
+// Created: 28 Apr 2014
+// Author: Natalia ERMOLAEVA
+
+#ifndef PartSet_TestOCC_H
+#define PartSet_TestOCC_H
+
+#include "PartSet.h"
+
+class XGUI_Workshop;
+class Handle_AIS_InteractiveContext;
+class Handle_V3d_View;
+
+/*!
+ \class PartSet_TestOCC
+ * \brief The operation to test OCC viewer work
+*/
+class PARTSET_EXPORT PartSet_TestOCC
+{
+public:
+ PartSet_TestOCC() {};
+
+ /// Creates a line feature, select it, modify the line. Check whether the highlight is correct.
+ /// \param the workshop to provide an access to the application information
+ static void testSelection(XGUI_Workshop* theWorkshop);
+
+ /// Creates row OCC presentation, activate in the local context, modify it and check selection
+ /// BUG: The result contains the selection from the first presentation
+ /// \param theContext a viewer interactive context
+ /// \param theContext a view
+ static void testSelection_OCC(Handle_AIS_InteractiveContext theContext,
+ Handle_V3d_View theView);
+
+ /// Creates row OCC presentation, activate in the local context, select it, erase the presentation
+ /// BUG: The selected shape are in the viewer even after erase
+ /// \param theContext a viewer interactive context
+ /// \param theContext a view
+ static void testErase_OCC(Handle_AIS_InteractiveContext theContext,
+ Handle_V3d_View theView);
+
+private:
+
+ /// Creates a temporary line
+ /// \param the workshop to get the operation manager and the displayer
+ static void createTestLine(XGUI_Workshop* theWorkshop);
+
+ /// Changes a temporary line
+ /// \param the workshop to get the operation manager and the displayer
+ static void changeTestLine(XGUI_Workshop* theWorkshop);
+
+ /// Emulates the mouse moving in the viewer
+ static void moveMouse(Handle_AIS_InteractiveContext theContext, Handle_V3d_View theView);
+};
+
+#endif
aContext->Display(anAIS, Standard_False);
if (isUpdateViewer)
- aContext->UpdateCurrentViewer();
+ UpdateViewer();
}*/
myFeature2AISObjectMap.erase(theFeature);
if (isUpdateViewer)
- aContext->UpdateCurrentViewer();
+ UpdateViewer();
}
void XGUI_Displayer::Redisplay(boost::shared_ptr<ModelAPI_Feature> theFeature,
// after. Another workaround to thrown down the selection and reselecting the AIS.
// If there was a problem here, try the first solution with close/open local context.
anAIS->Set(theShape);
- anAIS->Redisplay();
-
- /*if (aContext->IsSelected(anAIS)) {
- aContext->AddOrRemoveSelected(anAIS, false);
- aContext->AddOrRemoveSelected(anAIS, false);
- //aContext->SetSelected(anAIS, false);
- }*/
+ anAIS->Redisplay(Standard_True);
+ aContext->RecomputeSelectionOnly(anAIS);
}
}
else {
myFeature2AISObjectMap[theFeature] = anAIS;
aContext->Display(anAIS, false);
}
+ if (isUpdateViewer)
+ UpdateViewer();
}
void XGUI_Displayer::ActivateInLocalContext(boost::shared_ptr<ModelAPI_Feature> theFeature,
}
if (isUpdateViewer)
- aContext->UpdateCurrentViewer();
+ UpdateViewer();
}
void XGUI_Displayer::StopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
}
}
if (isUpdateViewer)
- aContext->UpdateCurrentViewer();
+ UpdateViewer();
}
void XGUI_Displayer::SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer)
}
if (isUpdateViewer)
- aContext->UpdateCurrentViewer();
+ UpdateViewer();
}
void XGUI_Displayer::EraseAll(const bool isUpdateViewer)
}
myFeature2AISObjectMap.clear();
if (isUpdateViewer)
- ic->UpdateCurrentViewer();
+ UpdateViewer();
}
void XGUI_Displayer::EraseDeletedFeatures(const bool isUpdateViewer)
}
if (isUpdateViewer)
- aContext->UpdateCurrentViewer();
+ UpdateViewer();
}
void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
CloseAllContexts(true);
}
-boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(Handle(AIS_InteractiveObject) theIO)
+Handle(AIS_InteractiveObject) XGUI_Displayer::GetAISObject(
+ boost::shared_ptr<ModelAPI_Feature> theFeature) const
+{
+ Handle(AIS_InteractiveObject) anIO;
+ if (myFeature2AISObjectMap.find(theFeature) != myFeature2AISObjectMap.end())
+ anIO = (myFeature2AISObjectMap.find(theFeature))->second;
+ return anIO;
+}
+
+boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(Handle(AIS_InteractiveObject) theIO) const
{
boost::shared_ptr<ModelAPI_Feature> aFeature;
FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
if (!ic.IsNull()) {
ic->CloseAllContexts(false);
if (isUpdateViewer)
- ic->UpdateCurrentViewer();
+ UpdateViewer();
}
}