// Initialization of color constants
int Colors::COLOR_BROWN = Quantity_NOC_BROWN;
+int Colors::COLOR_RED = Quantity_NOC_RED;
+int Colors::COLOR_GREEN = Quantity_NOC_GREEN;
+int Colors::COLOR_BLUE = Quantity_NOC_BLUE1;
GeomAPI_AISObject::GeomAPI_AISObject()
struct GEOMAPI_EXPORT Colors
{
static int COLOR_BROWN;
+ static int COLOR_RED;
+ static int COLOR_GREEN;
+ static int COLOR_BLUE;
};
/** \class GeomAPI_AISObject
#include <boost/shared_ptr.hpp>
#include <TopoDS_Shape.hxx>
#include <SelectMgr_EntityOwner.hxx>
+#include <AIS_InteractiveObject.hxx>
#include <ModelAPI_Result.h>
/// \return a shape instance
const TopoDS_Shape& shape() const { return myShape; }
+ void setInteractive(const Handle(AIS_InteractiveObject)& theIO) { myInteractive = theIO; }
+
+ Handle(AIS_InteractiveObject) interactive() const { return myInteractive; }
+
bool operator==(const ModuleBase_ViewerPrs& thePrs)
{
bool aResult = (myResult.get() == thePrs.object().get());
bool aOwner = (myOwner.Access() == thePrs.owner().Access());
bool aShape = myShape.IsEqual(thePrs.shape());
- return aResult && aOwner && aShape;
+ bool aIO = myInteractive == thePrs.interactive();
+ return aResult && aOwner && aShape && aIO;
}
private:
ObjectPtr myResult; /// the feature
Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner
TopoDS_Shape myShape; /// the shape
+ Handle(AIS_InteractiveObject) myInteractive;
};
#endif
#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)
{
{
PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
myWorkshop->operationMgr()->currentOperation());
- if (aPreviewOp)
- {
+ 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);
}
}
void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
{
+ erasePlanes();
myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
myWorkshop->actionsMgr()->update();
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)
{
boost::shared_ptr<SketchPlugin_Feature> aSPFeature =
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
if (aSPFeature) {
+ showPlanes();
//boost::shared_ptr<GeomAPI_AISObject> anAIS =
// aSPFeature->getAISObject(aDisplayer->getAISObject(aResult));
- aDisplayer->display(aSPFeature, false);
//aDisplayer->redisplay(aResult, anAIS, false);
}
}
{
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->firstResult(), aPreviewOp->getSelectionModes(theFeature),
isUpdateViewer);
- }
+ }*/
}
void PartSet_Module::updateCurrentPreview(const std::string& theCmdId)
class ModelAPI_Feature;
class XGUI_ViewerPrs;
class ModuleBase_Operation;
+class GeomAPI_AISObject;
class PARTSET_EXPORT PartSet_Module: public ModuleBase_IModule
{
//! Edits the feature
void editFeature(FeaturePtr theFeature);
+
+ //! Shopws working planes in viewer 3d
+ void showPlanes();
+ void erasePlanes();
+
private:
XGUI_Workshop* myWorkshop;
PartSet_Listener* myListener;
std::map<std::string, std::string> myFeaturesInFiles;
+
+ boost::shared_ptr<GeomAPI_AISObject> myXPlane;
+ boost::shared_ptr<GeomAPI_AISObject> myYPlane;
+ boost::shared_ptr<GeomAPI_AISObject> myZPlane;
};
#endif
using namespace std;
+
PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId,
QObject* theParent)
: PartSet_OperationSketchBase(theId, theParent)
const std::list<ModuleBase_ViewerPrs>& theSelected,
const std::list<ModuleBase_ViewerPrs>& theHighlighted)
{
- if (!hasSketchPlane()) {
- if (!theHighlighted.empty()) {
- ModuleBase_ViewerPrs aPrs = theHighlighted.front();
- const TopoDS_Shape& aShape = aPrs.shape();
- if (!aShape.IsNull())
- setSketchPlane(aShape);
- }
- }
- else {
+ if (hasSketchPlane()){
// if shift button is pressed and there are some already selected objects, the operation should
// not be started. We just want to combine some selected objects.
bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
const std::list<ModuleBase_ViewerPrs>& theSelected,
const std::list<ModuleBase_ViewerPrs>& theHighlighted)
{
- if (!hasSketchPlane()) {
- }
- else {
+ if (hasSketchPlane()) {
/// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape
/// but for other IO, for example constraint dimensions.
/// It is empty and we have to use the process mouse release to start edition operation
return hasSketchPlane();
}
+
void PartSet_OperationSketch::startOperation()
{
PartSet_OperationSketchBase::startOperation();
/// \return the boolean value whether the sketch is set
bool hasSketchPlane() const;
+ /// Set the plane to the current sketch
+ /// \param theShape the shape
+ void setSketchPlane(const TopoDS_Shape& theShape);
+
signals:
/// signal about the sketch plane is selected
/// \param theX the value in the X direction of the plane
/// Default impl calls corresponding slot and commits immediately.
virtual void startOperation();
- /// Set the plane to the current sketch
- /// \param theShape the shape
- void setSketchPlane(const TopoDS_Shape& theShape);
-
private:
std::list<ModuleBase_ViewerPrs> myFeatures; ///< the features to apply the edit operation
};
class SketchPlugin_Feature: public ModelAPI_Feature
{
public:
- /// Returns the AIS preview
- SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious) = 0;
-
/// Simple creation of interactive object by the result of the object
static boost::shared_ptr<GeomAPI_AISObject> simpleAISObject(
boost::shared_ptr<ModelAPI_Result> theRes, boost::shared_ptr<GeomAPI_AISObject> thePrevious);
#include <ModelAPI_ResultConstruction.h>
-const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color
-const double SKETCH_WIDTH = 4.0; /// the plane edge width
-
using namespace std;
-// face of the square-face displayed for selection of general plane
-const double PLANE_SIZE = 200;
-
SketchPlugin_Sketch::SketchPlugin_Sketch()
{
}
void SketchPlugin_Sketch::execute()
{
- if (!isPlaneSet()) {
- std::list<boost::shared_ptr<GeomAPI_Shape> > aFaces;
-
- addPlane(1, 0, 0, aFaces); // YZ plane
- addPlane(0, 1, 0, aFaces); // XZ plane
- addPlane(0, 0, 1, aFaces); // XY plane
- boost::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces);
- boost::shared_ptr<ModelAPI_ResultConstruction> aConstr =
- document()->createConstruction(data());
- aConstr->setShape(aCompound);
- setResult(aConstr);
- return;
- }
if (!data()->isValid())
return ;
boost::shared_ptr<ModelAPI_AttributeRefList> aRefList =
setResult(aConstr);
}
-boost::shared_ptr<GeomAPI_AISObject> SketchPlugin_Sketch::getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious)
-{
- boost::shared_ptr<GeomAPI_AISObject> aResult = simpleAISObject(firstResult(), thePrevious);
- aResult->setColor(SKETCH_PLANE_COLOR);
- aResult->setWidth(SKETCH_WIDTH);
- //anAIS->Redisplay();
- return aResult;
-}
-
const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature)
{
boost::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature)->setSketch(this);
data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature);
}
-void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ,
- std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const
-{
- boost::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
- boost::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(theX, theY, theZ));
- boost::shared_ptr<GeomAPI_Shape> aFace =
- GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE);
- theShapes.push_back(aFace);
-}
-
boost::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
{
boost::shared_ptr<GeomDataAPI_Point> aC =
#include <SketchPlugin_Feature.h>
#include <GeomAPI_Pnt.h>
#include <GeomAPI_Pln.h>
-#include <GeomAPI_IPresentable.h>
#include <list>
/**\class SketchPlugin_Sketch
* \ingroup DataModel
* \brief Feature for creation of the new part in PartSet.
*/
-class SketchPlugin_Sketch: public SketchPlugin_Feature, public GeomAPI_IPresentable
+class SketchPlugin_Sketch: public SketchPlugin_Feature
{
public:
/// Sketch feature kind
/// Request for initialization of data model of the feature: adding all attributes
SKETCHPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the AIS preview
- SKETCHPLUGIN_EXPORT virtual boost::shared_ptr<GeomAPI_AISObject> getAISObject(
- boost::shared_ptr<GeomAPI_AISObject> thePrevious);
-
/// Adds sub-feature of the higher level feature (sub-element of the sketch)
/// \param theFeature sub-feature
SKETCHPLUGIN_EXPORT virtual const void addSub(
/// \param theY the Y normal value
/// \param theZ the Z normal value
/// \param theShapes the list of result shapes
- void addPlane(double theX, double theY, double theZ,
- std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const;
+ //void addPlane(double theX, double theY, double theZ,
+ // std::list<boost::shared_ptr<GeomAPI_Shape> >& theShapes) const;
/// Checks whether the plane is set in the sketch.
/// \returns the boolean state
Handle(AIS_InteractiveObject) anAIS = anObject->impl<Handle(AIS_InteractiveObject)>();
if (!anAIS.IsNull()) {
aContext->Erase(anAIS, isUpdateViewer);
-
}
}
myResult2AISObjectMap.erase(theObject);
{
return myWorkshop->viewer()->AISContext();
}
+
+
+void XGUI_Displayer::display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
+ if (!anAISIO.IsNull())
+ aContext->Display(anAISIO, isUpdate);
+}
+
+void XGUI_Displayer::erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate)
+{
+ Handle(AIS_InteractiveContext) aContext = AISContext();
+ Handle(AIS_InteractiveObject) anAISIO = theAIS->impl<Handle(AIS_InteractiveObject)>();
+ if (!anAISIO.IsNull()) {
+ aContext->Remove(anAISIO, isUpdate);
+ }
+}
+
/// Returns true if the Feature succesfully displayed
void display(ObjectPtr theObject, bool isUpdateViewer = true);
+ /// Display the given AIS object. To hide this object use corresponde erase method
+ void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
+
/// Redisplay the shape and activate selection of sub-shapes
/// \param theFeature a feature instance
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
+ /// Erase the given AIS object displayed by corresponded display method
+ void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
+
/// Erase all presentations
/// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
//void EraseAll(const bool isUpdateViewer = true);
{
std::set<ObjectPtr> aPrsFeatures;
std::list<ModuleBase_ViewerPrs> aPresentations;
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) {
- Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
- TopoDS_Shape aShape = aContext->SelectedShape();
+ ModuleBase_ViewerPrs aPrs;
- if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
- continue;
-
- ObjectPtr aFeature = myWorkshop->displayer()->getObject(anIO);
- if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
- continue;
+ Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
+ aPrs.setInteractive(anIO);
+
+ ObjectPtr aFeature = aDisplayer->getObject(anIO);
+ if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) {
+ aPrs.setFeature(aFeature);
+ aPrsFeatures.insert(aFeature);
+ }
+ if (aContext->HasOpenedContext()) {
+ TopoDS_Shape aShape = aContext->SelectedShape();
+ if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip))
+ aPrs.setShape(aShape);
+ }
Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner();
- aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, anOwner));
- aPrsFeatures.insert(aFeature);
+ aPrs.setOwner(anOwner);
+ aPresentations.push_back(aPrs);
}
return aPresentations;
}
{
std::set<ObjectPtr> aPrsFeatures;
std::list<ModuleBase_ViewerPrs> aPresentations;
+ XGUI_Displayer* aDisplayer = myWorkshop->displayer();
Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
+ ModuleBase_ViewerPrs aPrs;
Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
- TopoDS_Shape aShape = aContext->DetectedShape();
- if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip)
- continue;
-
- ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO);
- if (aPrsFeatures.find(aResult) != aPrsFeatures.end())
- continue;
- aPresentations.push_back(ModuleBase_ViewerPrs(aResult, aShape, NULL));
- aPrsFeatures.insert(aResult);
+ aPrs.setInteractive(anIO);
+
+ ObjectPtr aResult = aDisplayer->getObject(anIO);
+ if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) {
+ aPrs.setFeature(aResult);
+ aPrsFeatures.insert(aResult);
+ }
+ if (aContext->HasOpenedContext()) {
+ TopoDS_Shape aShape = aContext->DetectedShape();
+ if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip)
+ aPrs.setShape(aShape);
+ }
+ aPresentations.push_back(aPrs);
}
-
return aPresentations;
}