#include <Geom_Plane.hxx>
#include <TopoDS_Shape.hxx>
#include <Quantity_NameOfColor.hxx>
+#include <BRepBndLib.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_LengthDimension.hxx>
{
Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl<gp_Pln>());
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ Handle(AIS_FixRelation) aFixPrs;
if (anAIS.IsNull()) {
- Handle(AIS_FixRelation) aFixPrs =
- new AIS_FixRelation(theShape->impl<TopoDS_Shape>(), aPlane);
+ aFixPrs = new AIS_FixRelation(aShape, aPlane);
setImpl(new Handle(AIS_InteractiveObject)(aFixPrs));
} else {
- Handle(AIS_PerpendicularRelation) aFixPrs =
- Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+ aFixPrs = Handle(AIS_FixRelation)::DownCast(anAIS);
if (!aFixPrs.IsNull()) {
- aFixPrs->SetFirstShape(theShape->impl<TopoDS_Shape>());
+ aFixPrs->SetFirstShape(aShape);
aFixPrs->SetPlane(aPlane);
aFixPrs->Redisplay(Standard_True);
}
}
+ if (!aFixPrs.IsNull()) {
+ Bnd_Box aBox;
+ BRepBndLib::Add(aShape, aBox);
+ double aXmin, aXmax, aYmin, aYmax, aZmin, aZmax;
+ aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+ gp_Pnt aXYZ1(aXmin, aXmax, aYmin);
+ gp_Pnt aXYZ2(aXmax, aYmax, aZmax);
+ double aDist = aXYZ1.Distance(aXYZ2);
+ if (aDist > Precision::Confusion()) {
+ aFixPrs->SetArrowSize(aDist/8.);
+ }
+ }
}
ObjectPtr aObject = aObjects.first();
if ((!mySelectedObject) && (!aObject))
return;
- if (mySelectedObject && aObject && mySelectedObject->isSame(aObject))
- return;
+
// Check that the selected object is result (others can not be accepted)
ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObject);
if (!aRes)
return;
+
+ if (myFeature) {
+ // We can not select a result of our feature
+ const std::list<boost::shared_ptr<ModelAPI_Result>>& aResList = myFeature->results();
+ std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
+ for (aIt = aResList.cbegin(); aIt != aResList.cend(); ++aIt) {
+ if ((*aIt) == aRes)
+ return;
+ }
+ }
+ // Check that object belongs to active document or PartSet
+ DocumentPtr aDoc = aRes->document();
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
+ return;
+
// Check that the result has a shape
GeomShapePtr aShape = ModelAPI_Tools::shape(aRes);
if (!aShape)
return;
}
setObject(aObject, aShape);
+ //activateSelection(false);
emit focusOutWidget(this);
}
}
//********************************************************************
void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape)
{
- if (mySelectedObject == theObj)
- return;
mySelectedObject = theObj;
myShape = theShape;
if (mySelectedObject) {
bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
{
ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
- if (myFeature) {
- // We can not select a result of our feature
- const std::list<boost::shared_ptr<ModelAPI_Result>>& aRes = myFeature->results();
- std::list<boost::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
- for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) {
- if ((*aIt) == aResult)
- return false;
- }
- }
- // Check that object belongs to active document or PartSet
- DocumentPtr aDoc = aResult->document();
- SessionPtr aMgr = ModelAPI_Session::get();
- if (!(aDoc == aMgr->activeDocument()) || (aDoc == aMgr->moduleDocument()))
- return false;
// Check that the shape of necessary type
boost::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
{
myWorkshop->viewer()->setViewProjection(theX, theY, theZ);
+}
+
+void PartSet_Module::onSketchLaunched()
+{
xWorkshop()->actionsMgr()->update();
// Set working plane
ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this,
SLOT(onPlaneSelected(double, double, double)));
connect(aSketchOp, SIGNAL(fitAllView()), this, SLOT(onFitAllView()));
+ connect(aSketchOp, SIGNAL(launchSketch()), this, SLOT(onSketchLaunched()));
}
}
/// \param the attribute of the feature
void onStorePoint2D(ObjectPtr theFeature, const std::string& theAttribute);
+ /// Called when sketch is launched
+ void onSketchLaunched();
+
protected slots:
/// Called on selection changed event
virtual void onSelectionChanged();
// We have to select a plane before any operation
TopoDS_Shape aShape = aPrs.shape();
if (!aShape.IsNull()) {
- setSketchPlane(aShape);
+ boost::shared_ptr<GeomAPI_Dir> aDir = setSketchPlane(aShape);
+ flushUpdated();
+ emit featureConstructed(feature(), FM_Hide);
// If selection is not a sketcher presentation then it has to be stored as
// External shape
if (feature() != aPrs.object()) {
- boost::shared_ptr<SketchPlugin_Sketch> aSketch =
- boost::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
- DataPtr aData = aSketch->data();
+ //boost::shared_ptr<SketchPlugin_Sketch> aSketch =
+ // boost::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
+ DataPtr aData = feature()->data();
AttributeSelectionPtr aSelAttr =
boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>
(aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
aSelAttr->setValue(aRes, aShapePtr);
}
}
+ } else {
+ // Turn viewer to the plane
+ emit planeSelected(aDir->x(), aDir->y(), aDir->z());
}
+ emit launchSketch();
}
}
}
return aHasPlane;
}
-void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
+boost::shared_ptr<GeomAPI_Dir> PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
{
if (theShape.IsNull())
- return;
+ return boost::shared_ptr<GeomAPI_Dir>();
// get selected shape
boost::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
aDirY->setValue(aYDir);
boost::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
-
- flushUpdated();
-
- emit featureConstructed(feature(), FM_Hide);
- emit planeSelected(aDir->x(), aDir->y(), aDir->z());
+ return aDir;
}
/// Set the plane to the current sketch
/// \param theShape the shape
- void setSketchPlane(const TopoDS_Shape& theShape);
+ /// \return selected direction
+ boost::shared_ptr<GeomAPI_Dir> setSketchPlane(const TopoDS_Shape& theShape);
/// Called on selection changed when the operation is active
virtual void selectionChanged(ModuleBase_ISelection* theSelection);
// signal about the viewer fit all perform
void fitAllView();
+ /// Signal to define sketch mode
+ void launchSketch();
+
protected:
/// Virtual method called when operation started (see start() method for more description)
/// Default impl calls corresponding slot and commits immediately.
#include "SketchPlugin_ConstraintRigid.h"
#include <ModelAPI_ResultConstruction.h>
+#include <Config_PropManager.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAlgoAPI_PointBuilder.h>
anAIS->createFixed(aShape, aPlane);
// Set color from preferences
- //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
- // PERPENDICULAR_COLOR);
- //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+ std::vector<int> aRGB = Config_PropManager::color("Visualization", "fixing_color",
+ FIXING_COLOR);
+ anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
return anAIS;
}
\ No newline at end of file
#include <SketchPlugin_Sketch.h>
#include <list>
+#define FIXING_COLOR "#ffff00"
+
/** \class SketchPlugin_ConstraintRigid
* \ingroup DataModel
* \brief Feature for creation of a new constraint which defines immovable object
Config_Prop::Color, LENGTH_COLOR);
Config_PropManager::registerProp("Visualization", "radius_color", "Radius color",
Config_Prop::Color, RADIUS_COLOR);
+ Config_PropManager::registerProp("Visualization", "fixing_color", "Fixing color",
+ Config_Prop::Color, FIXING_COLOR);
}
FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)