std::shared_ptr<GeomAPI_Pln> aPlane;
std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- if (aNormal && anOrigin) {
- double adX = aNormal->x();
- double adY = aNormal->y();
- double adZ = aNormal->z();
-
- if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
- double aX = anOrigin->x();
- double aY = anOrigin->y();
- double aZ = anOrigin->z();
- gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
- double aA, aB, aC, aD;
- aPln.Coefficients(aA, aB, aC, aD);
- aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+ if (aData) {
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ if (aNormal && anOrigin) {
+ double adX = aNormal->x();
+ double adY = aNormal->y();
+ double adZ = aNormal->z();
+
+ if ( (adX != 0) || (adY != 0) || (adZ != 0) ) { // Plane is valid
+ double aX = anOrigin->x();
+ double aY = anOrigin->y();
+ double aZ = anOrigin->z();
+ gp_Pln aPln(gp_Pnt(aX, aY, aZ), gp_Dir(adX, adY, adZ));
+ double aA, aB, aC, aD;
+ aPln.Coefficients(aA, aB, aC, aD);
+ aPlane = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
+ }
}
}
return aPlane;
std::dynamic_pointer_cast<SketchPlugin_Sketch>(theFeature);
if (aSketchFeature.get()) {
std::shared_ptr<ModelAPI_Data> aData = aSketchFeature->data();
- std::shared_ptr<GeomDataAPI_Dir> aNormal =
- std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
-
- aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
- aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+ if (aData) {
+ std::shared_ptr<GeomDataAPI_Dir> aNormal =
+ std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+
+ aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+ }
}
return aMsg;
}