X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Plugin.cpp;h=91a92ce7b2f89dd8498c70cd8c2b9066af0a7e37;hb=c3181094455d7e8f52d887b54dbfb798d4c4d210;hp=687e2cd94d0f8055ddaa4ed18a31a0d0ee90c281;hpb=0115fc33701117be0023dcf5d565ffba58365579;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index 687e2cd94..91a92ce7b 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -1,70 +1,185 @@ -#include "SketchPlugin_Plugin.h" -#include "SketchPlugin_Sketch.h" -#include "SketchPlugin_Line.h" -#include "SketchPlugin_Point.h" -#include "SketchPlugin_Circle.h" -#include "SketchPlugin_Arc.h" -#include "SketchPlugin_ConstraintCoincidence.h" -#include "SketchPlugin_ConstraintDistance.h" -#include "SketchPlugin_ConstraintLength.h" -#include "SketchPlugin_ConstraintParallel.h" -#include "SketchPlugin_ConstraintPerpendicular.h" -#include "SketchPlugin_ConstraintRadius.h" -#include "SketchPlugin_Validators.h" -#include +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include #include #include +#include + +#include + +#include + +#ifdef _DEBUG +#include +#endif + +//#define SET_PLANES_COLOR_IN_PREFERENCES using namespace std; // the only created instance of this plugin -static SketchPlugin_Plugin* MY_INSTANCE = new SketchPlugin_Plugin(); +static SketchPlugin_Plugin* MY_SKETCH_INSTANCE = new SketchPlugin_Plugin(); -SketchPlugin_Plugin::SketchPlugin_Plugin() +SketchPlugin_Plugin::SketchPlugin_Plugin() { - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - aFactory->registerValidator("SketchPlugin_DistanceFeatureValidator", new SketchPlugin_DistanceFeatureValidator); + aFactory->registerValidator("SketchPlugin_DistanceAttr", + new SketchPlugin_DistanceAttrValidator); + aFactory->registerValidator("SketchPlugin_ExternalValidator", + new SketchPlugin_ExternalValidator); + aFactory->registerValidator("SketchPlugin_TangentAttr", + new SketchPlugin_TangentAttrValidator); + aFactory->registerValidator("SketchPlugin_NotFixed", + new SketchPlugin_NotFixedValidator); + aFactory->registerValidator("SketchPlugin_EqualAttr", + new SketchPlugin_EqualAttrValidator); + aFactory->registerValidator("SketchPlugin_MirrorAttr", + new SketchPlugin_MirrorAttrValidator); // register this plugin - ModelAPI_PluginManager::get()->registerPlugin(this); + ModelAPI_Session::get()->registerPlugin(this); + + Config_PropManager::registerProp("Visualization", "sketch_entity_color", "Sketch enity color", + Config_Prop::Color, SKETCH_ENTITY_COLOR); + + Config_PropManager::registerProp("Visualization", "sketch_external_color", "Sketch external entity color", + Config_Prop::Color, SKETCH_EXTERNAL_COLOR); + + Config_PropManager::registerProp("Visualization", "sketch_auxiliary_color", "Sketch auxiliary entity color", + Config_Prop::Color, SKETCH_AUXILIARY_COLOR); + + Config_PropManager::registerProp("Visualization", "sketch_constraint_color", "Sketch constraint color", + Config_Prop::Color, SKETCH_CONSTRAINT_COLOR); + + Config_PropManager::registerProp("Visualization", "sketch_dimension_color", "Sketch dimension color", + Config_Prop::Color, SKETCH_DIMENSION_COLOR); + + // register sketcher properties +#ifdef SET_PLANES_COLOR_IN_PREFERENCES + Config_PropManager::registerProp("Visualization", "yz_plane_color", "YZ plane color", + Config_Prop::Color, YZ_PLANE_COLOR); + Config_PropManager::registerProp("Visualization", "xz_plane_color", "XZ plane color", + Config_Prop::Color, XZ_PLANE_COLOR); + Config_PropManager::registerProp("Visualization", "xy_plane_color", "XY plane color", + Config_Prop::Color, XY_PLANE_COLOR); +#endif } FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID) { if (theFeatureID == SketchPlugin_Sketch::ID()) { return FeaturePtr(new SketchPlugin_Sketch); - } - else if (theFeatureID == SketchPlugin_Point::ID()) { + } else if (theFeatureID == SketchPlugin_Point::ID()) { return FeaturePtr(new SketchPlugin_Point); - } - else if (theFeatureID == SketchPlugin_Line::ID()) { + } else if (theFeatureID == SketchPlugin_Line::ID()) { return FeaturePtr(new SketchPlugin_Line); - } - else if (theFeatureID == SketchPlugin_Circle::ID()) { + } else if (theFeatureID == SketchPlugin_Circle::ID()) { return FeaturePtr(new SketchPlugin_Circle); - } - else if (theFeatureID == SketchPlugin_Arc::ID()) { + } else if (theFeatureID == SketchPlugin_Arc::ID()) { return FeaturePtr(new SketchPlugin_Arc); - } - else if (theFeatureID == SketchPlugin_ConstraintCoincidence::ID()) { + } else if (theFeatureID == SketchPlugin_ConstraintCoincidence::ID()) { return FeaturePtr(new SketchPlugin_ConstraintCoincidence); - } - else if (theFeatureID == SketchPlugin_ConstraintDistance::ID()) { + } else if (theFeatureID == SketchPlugin_ConstraintDistance::ID()) { return FeaturePtr(new SketchPlugin_ConstraintDistance); - } - else if (theFeatureID == SketchPlugin_ConstraintLength::ID()) { + } else if (theFeatureID == SketchPlugin_ConstraintLength::ID()) { return FeaturePtr(new SketchPlugin_ConstraintLength); - } - else if (theFeatureID == SketchPlugin_ConstraintParallel::ID()) { + } else if (theFeatureID == SketchPlugin_ConstraintParallel::ID()) { return FeaturePtr(new SketchPlugin_ConstraintParallel); - } - else if (theFeatureID == SketchPlugin_ConstraintPerpendicular::ID()) { + } else if (theFeatureID == SketchPlugin_ConstraintPerpendicular::ID()) { return FeaturePtr(new SketchPlugin_ConstraintPerpendicular); - } - else if (theFeatureID == SketchPlugin_ConstraintRadius::ID()) { + } else if (theFeatureID == SketchPlugin_ConstraintRadius::ID()) { return FeaturePtr(new SketchPlugin_ConstraintRadius); + } else if (theFeatureID == SketchPlugin_ConstraintRigid::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintRigid); + } else if (theFeatureID == SketchPlugin_ConstraintHorizontal::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintHorizontal); + } else if (theFeatureID == SketchPlugin_ConstraintVertical::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintVertical); + } else if (theFeatureID == SketchPlugin_ConstraintEqual::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintEqual); + } else if (theFeatureID == SketchPlugin_ConstraintTangent::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintTangent); + } else if (theFeatureID == SketchPlugin_ConstraintMirror::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintMirror); + } else if (theFeatureID == SketchPlugin_ConstraintFillet::ID()) { + return FeaturePtr(new SketchPlugin_ConstraintFillet); } // feature of such kind is not found return FeaturePtr(); } + +void SketchPlugin_Plugin::processEvent(const std::shared_ptr& theMessage) +{ + const Events_ID kRequestEvent = + Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST); + if (theMessage->eventID() == kRequestEvent) { + std::shared_ptr aStateMessage = + std::dynamic_pointer_cast(theMessage); + Events_Loop::loop()->send(getFeaturesState(aStateMessage->feature()), false); + } +} + +std::shared_ptr SketchPlugin_Plugin +::getFeaturesState(const std::shared_ptr& theFeature) const +{ + const Events_ID kResponseEvent = Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE); + std::shared_ptr aMsg = + std::make_shared(kResponseEvent, this); + + bool aHasSketchPlane = false; + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(theFeature); + if (aSketchFeature.get()) { + std::shared_ptr aData = aSketchFeature->data(); + if (aData) { + std::shared_ptr aNormal = + std::dynamic_pointer_cast(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); + aMsg->setState(SketchPlugin_ConstraintHorizontal::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintVertical::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintEqual::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintTangent::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintMirror::ID(), aHasSketchPlane); + aMsg->setState(SketchPlugin_ConstraintFillet::ID(), aHasSketchPlane); + } + } + return aMsg; +}