2. Get rid compilation link from ModuleBase to BuildPlugin. Provide the same filtering functionality using corresponded validators.
return false;
}
+ /// remove objects of sub-type if ojects of correct type is in List, in some cases :
+ /// Wire builder: wires and edges selected
+ std::set<GeomAPI_Shape::ShapeType> shapeTypes;
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if (aShape.get())
+ shapeTypes.insert(aShape->shapeType());
+ }
+
+ std::set<int> aRemove;
+ if (shapeTypes.find(GeomAPI_Shape::WIRE) != shapeTypes.end())
+ {
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if (aShape.get()) {
+ auto aType = aShape->shapeType();
+ if (aType == GeomAPI_Shape::EDGE)
+ aRemove.insert(anIndex);
+ }
+ else
+ aRemove.insert(anIndex);
+ }
+ }
+
+ if (aRemove.size() > 0)
+ aSelectionList->remove(aRemove);
+
GeomAPI_Shape::ShapeType aShapeType = GeomAPI_Shape::shapeTypeByStr(theArguments.back());
// Collect base shapes.
return false;
}
+ /// remove objects of sub-type if ojects of correct type is in List, in some cases :
+ /// - Face builder: edges, faces and wires selected
+ /// --> remove edges and wires
+ std::set<GeomAPI_Shape::ShapeType> shapeTypes;
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if (aShape.get())
+ shapeTypes.insert(aShape->shapeType());
+ }
+
+ std::set<int> aRemove;
+ if (shapeTypes.find(GeomAPI_Shape::FACE) != shapeTypes.end())
+ {
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if (aShape.get()) {
+ auto aType = aShape->shapeType();
+ if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE)
+ aRemove.insert(anIndex);
+ }
+ else
+ aRemove.insert(anIndex);
+ }
+ }
+ if (aRemove.size() > 0)
+ aSelectionList->remove(aRemove);
+
bool hasEdgesOrWires = false;
bool hasFaces = false;
return false;
}
+ /// remove objects of sub-type if ojects of correct type is in List, in some cases :
+ /// Solid builder: faces and shapes shells or solids seleted
+ /// --> remove faces
+
+ std::set<GeomAPI_Shape::ShapeType> shapeTypes;
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if (aShape.get())
+ shapeTypes.insert(aShape->shapeType());
+ }
+
+ std::set<int> aRemove;
+ if (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() ||
+ shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() ||
+ shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end())
+ {
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if (aShape.get()) {
+ auto aType = aShape->shapeType();
+ if (aType == GeomAPI_Shape::FACE)
+ aRemove.insert(anIndex);
+ }
+ else
+ aRemove.insert(anIndex);
+ }
+ }
+
+ if (aRemove.size() > 0)
+ aSelectionList->remove(aRemove);
+
// Collect base shapes.
ListOfShape anOriginalShapes;
for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
}
}
-bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs)
{
- bool isCustomized = theDefaultPrs.get() != NULL &&
- theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+ bool isCustomized = false;
isCustomized = thePrs->setLineStyle(3) || isCustomized;
isCustomized = thePrs->setWidth(2) || isCustomized;
ConstructionPlugin_Axis();
/// Customize presentation of the feature
- virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs);
protected:
/// Creates a new axis by two defined points
}
//==================================================================================================
-bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+bool ConstructionPlugin_Plane::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs)
{
std::vector<int> aColor;
// get color from the attribute of the result
}
}
if (aColor.empty())
- aColor = Config_PropManager::color("Visualization", "construction_plane_color");
+ aColor = Config_PropManager::color("Visualization", COLOR_NAME());
bool isCustomized = false;
if (aColor.size() == 3)
return CONSTRUCTION_PLANE_COLOR;
}
+ /// Default color property name.
+ inline static const std::string& COLOR_NAME()
+ {
+ static const std::string PLANE_COLOR_NAME("construction_plane_color");
+ return PLANE_COLOR_NAME;
+ }
+
/// Plane kind.
inline static const std::string& ID()
{
ConstructionPlugin_Plane();
/// Customize presentation of the feature
- virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs);
protected:
/// Creates a new plane by general equation.
ModelAPI_Session::get()->registerPlugin(this);
// register construction properties
- Config_PropManager::registerProp("Visualization", "construction_plane_color",
- "Construction plane color",
- Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
+ Config_PropManager::registerProp("Visualization", ConstructionPlugin_Plane::COLOR_NAME(),
+ "Construction plane color", Config_Prop::Color, ConstructionPlugin_Plane::DEFAULT_COLOR());
+
+ Config_PropManager::registerProp("Visualization", ConstructionPlugin_Point::COLOR_NAME(),
+ "Construction point color", Config_Prop::Color, ConstructionPlugin_Point::DEFAULT_COLOR());
}
FeaturePtr ConstructionPlugin_Plugin::createFeature(std::string theFeatureID)
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultConstruction.h>
#include <GeomAPI_Pln.h>
#include <GeomAPI_ShapeIterator.h>
+#include <Config_PropManager.h>
+
//==================================================================================================
ConstructionPlugin_Point::ConstructionPlugin_Point()
{
std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
aConstr->setInfinite(true);
aConstr->setShape(aShape);
- /// set point color
- aConstr->setColor(ModelAPI_ResultConstruction::ModelApi_PointColor::DEFAULT_COLOR(),
- ModelAPI_ResultConstruction::ModelApi_PointColor::COLOR_CONFIG_NAME());
setResult(aConstr);
}
//==================================================================================================
bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
- AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
+ AISObjectPtr thePrs)
{
- bool isCustomized = theDefaultPrs.get() != NULL &&
- theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
+ std::vector<int> aColor;
+ // get color from the attribute of the result
+ if (theResult.get() != NULL &&
+ theResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+ AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() && aColorAttr->size()) {
+ aColor.push_back(aColorAttr->value(0));
+ aColor.push_back(aColorAttr->value(1));
+ aColor.push_back(aColorAttr->value(2));
+ }
+ }
+ if (aColor.empty())
+ aColor = Config_PropManager::color("Visualization", COLOR_NAME());
+
+ bool isCustomized = false;
+ if (aColor.size() == 3)
+ isCustomized = thePrs->setColor(aColor[0], aColor[1], aColor[2]);
//thePrs->setPointMarker(1, 1.); // Set point as a '+' symbol
return isCustomized;
}
/// Returns the kind of a feature.
CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind();
+ /// Default color for a point.
+ inline static const std::string& DEFAULT_COLOR()
+ {
+ static const std::string POINT_COLOR("85,85,0");
+ return POINT_COLOR;
+ }
+
+ /// Default color property name.
+ inline static const std::string& COLOR_NAME()
+ {
+ static const std::string POINT_COLOR_NAME("construction_point_color");
+ return POINT_COLOR_NAME;
+ }
+
+
/// Point kind.
inline static const std::string& ID()
{
ConstructionPlugin_Point();
/// Customize presentation of the feature
- virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
+ virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs);
private:
std::shared_ptr<GeomAPI_Vertex> createByXYZ();
/// Modifies the given presentation in the custom way.
virtual bool customisePresentation(std::shared_ptr<ModelAPI_Result> theResult,
- AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs) = 0;
+ AISObjectPtr thePrs) = 0;
};
typedef std::shared_ptr<GeomAPI_ICustomPrs> GeomCustomPrsPtr;
std::string& theDefault)
{
theSection = "Visualization";
- theName = getColorConfigName();
- theDefault = getColor();
+ theName = RESULT_COLOR_NAME();
+ theDefault = DEFAULT_COLOR();
}
void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
{
return group();
}
-
-ModelAPI_ResultConstruction::ModelAPI_ResultConstruction(){
- setColor(DEFAULT_COLOR(), DEFAULT_COLOR_CONFIG_NAME());
-}
* Provides a shape that may be displayed in the viewer.
* Intermediate, light result that in many cases produces a result on the fly.
*/
-MODELAPI_EXPORT class ModelAPI_ResultConstruction : public ModelAPI_Result
+class ModelAPI_ResultConstruction : public ModelAPI_Result
{
public:
- MODELAPI_EXPORT ModelAPI_ResultConstruction();
-
/// Returns the group identifier of this result
MODELAPI_EXPORT virtual std::string groupName();
return RESULT_CONSTRUCTION_COLOR;
}
+ /// default color for a result construction
+ inline static const std::string& RESULT_COLOR_NAME()
+ {
+ static const std::string COLOR_NAME("result_construction_color");
+ return COLOR_NAME;
+ }
+
/// default deflection for a result construction
inline static const std::string DEFAULT_DEFLECTION()
{
virtual bool isInfinite() = 0;
/// Sets the flag that it is infinite
virtual void setInfinite(const bool theInfinite) = 0;
-
- /*************************************************************************/
- /// Changes for custom point color
-
- inline static const std::string& DEFAULT_COLOR_CONFIG_NAME()
- {
- static const std::string RESULT_CONSTRUCTION_COLOR_CONFIG_NAME("result_construction_color");
- return RESULT_CONSTRUCTION_COLOR_CONFIG_NAME;
- }
-
- inline void setColor(const std::string myColor, const std::string & myColorConfigName)
- {
- color = myColor;
- colorConfigName = myColorConfigName;
- }
-
- inline const std::string & getColor() const
- {
- return color;
- }
-
- inline const std::string & getColorConfigName() const
- {
- return colorConfigName;
- }
-
-private:
- std::string color;
- std::string colorConfigName;
-
-public:
-
- /// Specific properties for point
- class ModelApi_PointColor
- {
- public:
- /// default color for a point construction
- inline static const std::string& DEFAULT_COLOR()
- {
- static const std::string POINT_CONSTRUCTION_COLOR("85,85,0");
- return POINT_CONSTRUCTION_COLOR;
- }
-
- inline static const std::string COLOR_CONFIG_NAME()
- {
- static const std::string POINT_CONFIG_COLOR_NAME("result_point_color");
- return POINT_CONFIG_COLOR_NAME;
- }
- };
- /*************************************************************************/
};
//! Pointer on feature object
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
${PROJECT_SOURCE_DIR}/src/Locale
- ${PROJECT_SOURCE_DIR}/src/BuildPlugin
${SUIT_INCLUDE}
)
#include <ModelAPI_Tools.h>
#include <ModelAPI_AttributeSelection.h>
-#include <BuildPlugin_Face.h>
-#include <BuildPlugin_Wire.h>
-#include <BuildPlugin_Solid.h>
-
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <StdSelect_BRepOwner.hxx>
filterCompSolids(aSelected);
- if (myFeatureId == BuildPlugin_Face::ID() || myFeatureId == BuildPlugin_Wire::ID() ||
- myFeatureId == BuildPlugin_Solid::ID())
- {
- /// remove objects of sub-type if ojects of correct type is in List, in some cases :
- /// - Face builder: edges, faces and wires selected
- /// --> remove edges and wires
- /// Wire builder: wires and edges selected
- /// --> remove egdes
- /// Solid builder: faces and shapes shells or solids seleted
- /// --> remove faces
-
- std::set<GeomAPI_Shape::ShapeType> shapeTypes;
- for (auto aSelection: aSelected){
- auto aShape = aSelection->shape();
- if (aShape)
- shapeTypes.insert(aShape->shapeType());
- }
-
- std::vector<ModuleBase_ViewerPrsPtr> aRemove;
-
- if (myFeatureId == BuildPlugin_Face::ID() && shapeTypes.find(GeomAPI_Shape::FACE)
- != shapeTypes.end())
- {
- for(auto aSelection: aSelected){
- auto aType = aSelection->shape()->shapeType();
- if (aType == GeomAPI_Shape::WIRE || aType == GeomAPI_Shape::EDGE)
- aRemove.push_back(aSelection);
- }
- }
- else if (myFeatureId == BuildPlugin_Wire::ID() && shapeTypes.find(GeomAPI_Shape::WIRE)
- != shapeTypes.end())
- {
- for(auto aSelection: aSelected){
- auto aType = aSelection->shape()->shapeType();
- if (aType == GeomAPI_Shape::EDGE)
- aRemove.push_back(aSelection);
- }
- }
- else if (myFeatureId == BuildPlugin_Solid::ID() &&
- (shapeTypes.find(GeomAPI_Shape::SHAPE) != shapeTypes.end() ||
- shapeTypes.find(GeomAPI_Shape::SOLID) != shapeTypes.end() ||
- shapeTypes.find(GeomAPI_Shape::SHELL) != shapeTypes.end()) )
- {
- for(auto aSelection: aSelected){
- auto aType = aSelection->shape()->shapeType();
- if( aType == GeomAPI_Shape::FACE)
- aRemove.push_back(aSelection);
- }
- }
-
- for(auto aSelection: aRemove){
- aSelected.removeOne(aSelection);
- }
- }
-
return aSelected;
}
setDefaultConstraintShown();
- //Config_PropManager::registerProp("Visualization", "object_default_color", "Object color",
- // Config_Prop::Color, "225,225,225");
-
Config_PropManager::registerProp("Visualization", "result_body_color", "Result color",
Config_Prop::Color, ModelAPI_ResultBody::DEFAULT_COLOR());
Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
- Config_PropManager::registerProp("Visualization",
- ModelAPI_ResultConstruction::DEFAULT_COLOR_CONFIG_NAME(),
- "Construction color", Config_Prop::Color,
- ModelAPI_ResultConstruction::DEFAULT_COLOR());
-
- Config_PropManager::registerProp(
- "Visualization",
- ModelAPI_ResultConstruction::ModelApi_PointColor::COLOR_CONFIG_NAME(),
- "Construction point color", Config_Prop::Color,
- ModelAPI_ResultConstruction::ModelApi_PointColor::DEFAULT_COLOR());
-
+ Config_PropManager::registerProp("Visualization", ModelAPI_ResultConstruction::RESULT_COLOR_NAME(),
+ "Construction color", Config_Prop::Color, ModelAPI_ResultConstruction::DEFAULT_COLOR());
Config_PropManager::registerProp("Visualization", "result_part_color", "Part color",
Config_Prop::Color, ModelAPI_ResultPart::DEFAULT_COLOR());
return anAIS;
}
-//******************************************************
-void getResultColor(const ResultPtr& theResult, std::vector<int>& theColor)
-{
- ModelAPI_Tools::getColor(theResult, theColor);
- if (theColor.empty())
- PartSet_Tools::getDefaultColor(theResult, false, theColor);
-}
-
//******************************************************
double getResultDeflection(const ResultPtr& theResult)
{
}
else {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
if (aResult.get()) {
std::vector<int> aColor;
- getResultColor(aResult, aColor);
-
- SessionPtr aMgr = ModelAPI_Session::get();
- if (aMgr->activeDocument() != aResult->document()) {
+ bool isSameDoc = (ModelAPI_Session::get()->activeDocument() == aResult->document());
+ // Get user defined color for the object
+ ModelAPI_Tools::getColor(aResult, aColor);
+ if (isSameDoc) {
+ bool isCustomized = false;
+ if (aColor.empty() && aFeature.get()) {
+ GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+ if (aCustPrs.get()) {
+ isCustomized = aCustPrs->customisePresentation(aResult, thePrs);
+ }
+ }
+ if (!isCustomized) {
+ if (aColor.empty()) {
+ PartSet_Tools::getDefaultColor(aResult, false, aColor);
+ }
+ thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+ }
+ }
+ else {
+ if (aColor.empty()) {
+ PartSet_Tools::getDefaultColor(aResult, false, aColor);
+ }
QColor aQColor(aColor[0], aColor[1], aColor[2]);
QColor aNewColor =
QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF() / 3., aQColor.valueF());
- aColor[0] = aNewColor.red();
- aColor[1] = aNewColor.green();
- aColor[2] = aNewColor.blue();
+ thePrs->setColor(aNewColor.red(), aNewColor.green(), aNewColor.blue());
}
- thePrs->setColor(aColor[0], aColor[1], aColor[2]);
-
thePrs->setDeflection(getResultDeflection(aResult));
-
thePrs->setTransparency(getResultTransparency(aResult));
/// set texture parameters
- if(aResult->hasTextureFile()){
+ if(aResult->hasTextureFile()) {
setTexture(aResult->getTextureFile(), thePrs);
}
}
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- if (aFeature.get()) {
- if (aFeature->getKind() == SketchPlugin_Sketch::ID())
+ if (aFeature.get() && (aFeature->getKind() == SketchPlugin_Sketch::ID())) {
thePrs->setWidth(2);
}
}
{
theColor.clear();
// get default color from the preferences manager for the given result
- if (theColor.empty()) {
- std::string aSection, aName, aDefault;
- theObject->colorConfigInfo(aSection, aName, aDefault);
- if (!aSection.empty() && !aName.empty()) {
- theColor = Config_PropManager::color(aSection, aName);
- }
+ std::string aSection, aName, aDefault;
+ theObject->colorConfigInfo(aSection, aName, aDefault);
+ if (!aSection.empty() && !aName.empty()) {
+ theColor = Config_PropManager::color(aSection, aName);
}
if (!isEmptyColorValid && theColor.empty()) {
// all AIS objects, where the color is not set, are in black.
* Some feature's methods implemented here as dummy to
* Base class for all constraints.
*/
-class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable,
- public GeomAPI_ICustomPrs
+class SketchPlugin_ConstraintBase : public SketchPlugin_Constraint, public GeomAPI_IPresentable
{
- public:
- /// Customize presentation of the feature
- virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs)
- {
- return theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs);
- }
-
protected:
/// \brief Use plugin manager for features creation
SketchPlugin_ConstraintBase()
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
if (aResult.get()) {
ModelAPI_Tools::getColor(aResult, aColor);
- if (aColor.empty())
+ if (aColor.empty()) {
+ AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+ if (anAISObj.get()) {
+ aColor.resize(3);
+ anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
+ }
+ }
+ if (aColor.empty()) {
getDefaultColor(aResult, false, aColor);
- }
- else {
- // TODO: remove the obtaining a color from the AIS object
- // this does not happen never because:
- // 1. The color can be changed only on results
- // 2. The result can be not visualized in the viewer(e.g. Origin Construction)
- AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
- if (anAISObj.get()) {
- aColor.resize(3);
- anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
}
}
- if (!aColor.empty())
- break;
}
if (aColor.size() != 3)
return;