#include <PartSet_Listener.h>
#include <PartSet_TestOCC.h>
#include <PartSet_WidgetSketchLabel.h>
+#include <PartSet_Validators.h>
#include <ModuleBase_Operation.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Validator.h>
#include <ModelAPI_Data.h>
#include <GeomDataAPI_Point2D.h>
#include <XGUI_Workshop.h>
#include <XGUI_OperationMgr.h>
#include <XGUI_SelectionMgr.h>
+#include <XGUI_Selection.h>
#include <XGUI_ViewPort.h>
#include <XGUI_ActionsMgr.h>
#include <XGUI_ViewerProxy.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_AISObject.h>
+#include <AIS_Shape.hxx>
#include <QObject>
#include <QMouseEvent>
#include <QString>
+#include <GeomAlgoAPI_FaceBuilder.h>
+#include <GeomDataAPI_Dir.h>
+
#ifdef _DEBUG
#include <QDebug>
#endif
+
+//const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color
+const double SKETCH_WIDTH = 4.0; /// the plane edge width
+// face of the square-face displayed for selection of general plane
+const double PLANE_SIZE = 200;
+
+
/*!Create and return new instance of XGUI_Module*/
extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop)
{
Config_ModuleReader aXMLReader = Config_ModuleReader();
aXMLReader.readAll();
myFeaturesInFiles = aXMLReader.featuresInFiles();
+
+ //!! Test registering of validators
+ PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ aFactory->registerValidator("PartSet_DistanceValidator", new PartSet_DistanceValidator);
+ aFactory->registerValidator("PartSet_LengthValidator", new PartSet_LengthValidator);
+ aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
+ aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
+ aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
}
void PartSet_Module::featureCreated(QAction* theFeature)
ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp) {
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ XGUI_Selection* aSelection = myWorkshop->selector()->selection();
// Initialise operation with preliminary selection
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected();
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted();
+ std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
aPreviewOp->initSelection(aSelected, aHighlighted);
}
sendOperation(anOperation);
void PartSet_Module::onContextMenuCommand(const QString& theId, bool isChecked)
{
- QFeatureList aFeatures = myWorkshop->selector()->selectedFeatures();
+ QList<ObjectPtr> aFeatures = myWorkshop->selector()->selection()->selectedObjects();
if (theId == "EDIT_CMD" && (aFeatures.size() > 0)) {
- editFeature(aFeatures.first());
+ FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aFeatures.first());
+ if (aFeature)
+ editFeature(aFeature);
}
}
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
myWorkshop->operationMgr()->currentOperation());
if (aPreviewOp) {
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected();
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted();
+ XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ // Initialise operation with preliminary selection
+ std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
}
{
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
myWorkshop->operationMgr()->currentOperation());
- if (aPreviewOp)
- {
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected();
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted();
+ if (aPreviewOp) {
+ XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ // Initialise operation with preliminary selection
+ std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
- aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
+ PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
+ if (aSketchOp) {
+ if ((!aSketchOp->hasSketchPlane()) && (aSelected.size() > 0)) {
+ Handle(AIS_InteractiveObject) aAIS = aSelected.front().interactive();
+ if ((aAIS == myXPlane->impl<Handle(AIS_InteractiveObject)>()) ||
+ (aAIS == myYPlane->impl<Handle(AIS_InteractiveObject)>()) ||
+ (aAIS == myZPlane->impl<Handle(AIS_InteractiveObject)>()) ) {
+
+ Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAIS);
+ aSketchOp->setSketchPlane(aAISShape->Shape());
+ }
+ }
+ } else
+ aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
}
}
myWorkshop->operationMgr()->currentOperation());
if (aPreviewOp)
{
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected();
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted();
+ XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ // Initialise operation with preliminary selection
+ std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
aPreviewOp->mouseDoubleClick(theEvent, myWorkshop->viewer()->activeView(), aSelected,
aHighlighted);
}
void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
{
+ erasePlanes();
myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
myWorkshop->actionsMgr()->update();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
if (aPreviewOp)
{
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- // refill the features list with avoiding of the features, obtained only by vertex shape (TODO)
- std::list<XGUI_ViewerPrs> aSelected = aDisplayer->getSelected();
- std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->getHighlighted();
+ XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ // Initialise operation with preliminary selection
+ std::list<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
+ std::list<ModuleBase_ViewerPrs> aHighlighted = aSelection->getHighlighted();
aPreviewOp->initFeature(theFeature);
aPreviewOp->initSelection(aSelected, aHighlighted);
} else {
activateFeature((*anIt), false);
}
}
- aDisplayer->stopSelection(theFeatures, isStop, false);
+ QResultList aResults;
+ foreach(FeaturePtr aFeature, theFeatures) {
+ if (aFeature->results().size() > 0) {
+ const std::list<ResultPtr>& aResList = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt)
+ aResults.append(*aIt);
+ }
+ }
+ aDisplayer->stopSelection(aResults, isStop, false);
XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
aViewer->enableSelection(!isStop);
aDisplayer->updateViewer();
}
-void PartSet_Module::onSetSelection(const QFeatureList& theFeatures)
+void PartSet_Module::onSetSelection(const QResultList& theFeatures)
{
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
aDisplayer->setSelected(theFeatures, false);
void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode)
{
bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide;
- visualizePreview(theFeature, isDisplay, false);
+ // TODO visualizePreview(theFeature, isDisplay, false);
if (!isDisplay) {
ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation();
FeaturePtr aSketch;
std::list<FeaturePtr>::const_iterator anIt = aList.begin(),
aLast = aList.end();
for (; anIt != aLast; anIt++)
- visualizePreview(*anIt, false, false);
+ visualizePreview((*anIt), false, false);
aDisplayer->updateViewer();
}
}
Events_Loop::loop()->send(aMessage);
}
+boost::shared_ptr<GeomAPI_Shape> getPlane(double theX, double theY, double theZ)
+{
+ boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
+ boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
+ return GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
+}
+
+void PartSet_Module::showPlanes()
+{
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ // Show selection planes
+ if (!myXPlane) {
+ boost::shared_ptr<GeomAPI_Shape> aPlaneX = getPlane(1, 0, 0);
+ myXPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
+ myXPlane->createShape(aPlaneX);
+ myXPlane->setColor(Colors::COLOR_RED);
+ myXPlane->setWidth(SKETCH_WIDTH);
+ }
+ if (!myYPlane) {
+ boost::shared_ptr<GeomAPI_Shape> aPlaneY = getPlane(0, 1, 0);
+ myYPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
+ myYPlane->createShape(aPlaneY);
+ myYPlane->setColor(Colors::COLOR_GREEN);
+ myYPlane->setWidth(SKETCH_WIDTH);
+ }
+ if (!myZPlane) {
+ boost::shared_ptr<GeomAPI_Shape> aPlaneZ = getPlane(0, 0, 1);
+ myZPlane = boost::shared_ptr<GeomAPI_AISObject>(new GeomAPI_AISObject());
+ myZPlane->createShape(aPlaneZ);
+ myZPlane->setColor(Colors::COLOR_BLUE);
+ myZPlane->setWidth(SKETCH_WIDTH);
+ }
+ aDisplayer->display(myXPlane, false);
+ aDisplayer->display(myYPlane, false);
+ aDisplayer->display(myZPlane, false);
+ aDisplayer->updateViewer();
+}
+
+void PartSet_Module::erasePlanes()
+{
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+ aDisplayer->erase(myXPlane, false);
+ aDisplayer->erase(myYPlane, false);
+ aDisplayer->erase(myZPlane, false);
+ aDisplayer->updateViewer();
+}
+
void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay,
const bool isUpdateViewer)
{
if (!aPreviewOp)
return;
+ ResultPtr aResult = theFeature->firstResult();
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
if (isDisplay) {
boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
- if (aSPFeature)
- {
- boost::shared_ptr<GeomAPI_AISObject> anAIS =
- aSPFeature->getAISObject(aDisplayer->getAISObject(theFeature));
- aDisplayer->redisplay(theFeature, anAIS, false);
+ if (aSPFeature) {
+ showPlanes();
+ //boost::shared_ptr<GeomAPI_AISObject> anAIS =
+ // aSPFeature->getAISObject(aDisplayer->getAISObject(aResult));
+ //aDisplayer->redisplay(aResult, anAIS, false);
}
}
else
- aDisplayer->erase(theFeature, false);
+ aDisplayer->erase(aResult, false);
if (isUpdateViewer)
aDisplayer->updateViewer();
{
ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
- if (aPreviewOp) {
+/* TODO if (aPreviewOp) {
XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature),
+ aDisplayer->activateInLocalContext(theFeature->firstResult(), aPreviewOp->getSelectionModes(theFeature),
isUpdateViewer);
- }
+ }*/
}
void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
boost::dynamic_pointer_cast<SketchPlugin_Feature>(*anIt);
if (!aSPFeature)
continue;
- visualizePreview(*anIt, true, false);
- aDisplayer->activateInLocalContext(*anIt, aModes, false);
+ visualizePreview((*anIt), true, false);
+ aDisplayer->activateInLocalContext((*anIt)->firstResult(), aModes, false);
}
aDisplayer->updateViewer();
}
return;
// if (theFeature->getKind() == SKETCH_KIND) {
- FeaturePtr aFeature = theFeature;
- if (XGUI_Tools::isModelObject(aFeature)) {
- ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
- aFeature = aObject->featureRef();
- }
-
- if (aFeature) {
- onLaunchOperation(aFeature->getKind(), aFeature);
- updateCurrentPreview(aFeature->getKind());
- }
+ //FeaturePtr aFeature = theFeature;
+ //if (XGUI_Tools::isModelObject(aFeature)) {
+ // ObjectPtr aObject = boost::dynamic_pointer_cast<ModelAPI_Object>(aFeature);
+ // aFeature = aObject->featureRef();
+ //}
+
+ //if (aFeature) {
+ onLaunchOperation(theFeature->getKind(), theFeature);
+ updateCurrentPreview(theFeature->getKind());
+ //}
// }
}