diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 337e1676..8cd217a1 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -182,3 +182,25 @@ void Entity::SetParent(Entity* parent) { SetWorkspace(workSpace); parent_->childer_.push_back(this); } + +void Entity::SetVisible(bool v) { + LOG_INFO("set visible: {}", v); + if (nullptr == rootComponet_) { + LOG_WARN("rootComponet_ is nullptr"); + return; + } + + rootComponet_->SetVisible(v); + for (auto item : childer_) { + item->SetVisible(v); + } +} + +bool Entity::IsVisible() const { + if (nullptr == rootComponet_) { + LOG_WARN("rootComponet_ is nullptr"); + return false; + } + + return rootComponet_->IsVisible(); +} diff --git a/src/entities/Entity.h b/src/entities/Entity.h index 4ee236ff..37bee874 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -68,6 +68,9 @@ public: return childer_; } + void SetVisible(bool v); + bool IsVisible() const; + Q_SIGNALS: void NameChanged(const QString& name); diff --git a/src/entities/SceneComponent.cpp b/src/entities/SceneComponent.cpp index 02c67721..cf2a05e9 100644 --- a/src/entities/SceneComponent.cpp +++ b/src/entities/SceneComponent.cpp @@ -261,3 +261,19 @@ void SceneComponent::AddToRender() { AttachParent(parent); } } + +void SceneComponent::SetVisible(bool v) { + visible_ = v; + if (nullptr == mt_) { + return; + } + mt_->setNodeMask(v ? ~0 : 0); + + // for (auto child : children_) { + // child->SetVisible(v); + // } +} + +bool SceneComponent::IsVisible() const { + return visible_; +} diff --git a/src/entities/SceneComponent.h b/src/entities/SceneComponent.h index a6999e69..95ef0cb9 100644 --- a/src/entities/SceneComponent.h +++ b/src/entities/SceneComponent.h @@ -60,6 +60,9 @@ public: void AttachParent(SceneComponent* parent); void UpdateLocationAndRotation(); + void SetVisible(bool v); + bool IsVisible() const; + protected: void RemoveRender(); void RemoveParent(); @@ -75,4 +78,5 @@ protected: protected: Transform transform_; + bool visible_{ true }; }; \ No newline at end of file diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index e1ab814e..5d1179ac 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -809,12 +809,12 @@ - + ModelBase - + color base @@ -944,48 +944,48 @@ QtConeWaveComponentManager - - + + ConeWaveComponent - + Height - + Radius - + waveCount - + waveSpeed - + baseColor - + waveColor - + ringBrightAlpha - + ringDarkAlpha @@ -1091,28 +1091,28 @@ QtDashedLineComponentManager - - + + DashedLineComponent - + Start - + End - + Radius - + Color @@ -1128,12 +1128,17 @@ QtEntityPropertyManager - + Name - + + Visible + + + + Transform @@ -1215,13 +1220,13 @@ QtMeshComponetManager - - + + MeshComponent - + Mesh @@ -1229,25 +1234,30 @@ QtModelBasePropertyManager - + Name - + Description - + Inflow - + InnerBottomElevation + + + Visible + + QtOsgViewWidget @@ -1265,13 +1275,13 @@ QtPathComponentManager - - + + PathComponent - + Path @@ -1521,42 +1531,42 @@ QtWorkspacePropertyManager - + Name - + Description - + Timestep - + SimMatlab - + MatlabParam - + Wave - + RD - + Report diff --git a/src/ui/PropertyBrowser.cpp b/src/ui/PropertyBrowser.cpp index bc375518..03c41f19 100644 --- a/src/ui/PropertyBrowser.cpp +++ b/src/ui/PropertyBrowser.cpp @@ -120,6 +120,8 @@ void PropertyBrowser::InitUI() { } void PropertyBrowser::InitPropertyManager() { + intManager_ = new QtIntPropertyManager(this); + boolManager_ = new QtBoolPropertyManager(this); doubleManager_ = new QtDoublePropertyManager(this); stringManager_ = new QtStringPropertyManager(this); colorManager_ = new QtColorPropertyManager(this); @@ -138,6 +140,8 @@ void PropertyBrowser::InitPropertyManager() { QtFilePathFactory* filePathFactory = new QtFilePathFactory(this); //QtTransfromEditorFactory* transformFactory = new QtTransfromEditorFactory(this); + browser_->setFactoryForManager(intManager_, spinBoxFactory); + browser_->setFactoryForManager(boolManager_, checkBoxFactory); browser_->setFactoryForManager(doubleManager_, doubleSpinBoxFactory); browser_->setFactoryForManager(stringManager_, lineEditFactory); browser_->setFactoryForManager(colorManager_->subIntPropertyManager(), spinBoxFactory); @@ -210,7 +214,7 @@ void PropertyBrowser::Test() { QtProperty* property; property = modelBaseManager_->addProperty(tr("ModelBase")); - QModelAttbute modelAttr(QString("test"), QString("test222"), true, 1.0 ); + QModelAttbute modelAttr(QString("test"), QString("test222"), true, 1.0 , true); modelBaseManager_->setValue(property, modelAttr); addProperty(property, QLatin1String("brush")); diff --git a/src/ui/PropertyBrowser.h b/src/ui/PropertyBrowser.h index cd24055d..770529c2 100644 --- a/src/ui/PropertyBrowser.h +++ b/src/ui/PropertyBrowser.h @@ -32,6 +32,8 @@ private: private: class QtTreePropertyBrowser* browser_{ nullptr }; + class QtIntPropertyManager* intManager_{ nullptr }; + class QtBoolPropertyManager* boolManager_{ nullptr }; class QtDoublePropertyManager* doubleManager_{ nullptr }; class QtStringPropertyManager* stringManager_{ nullptr }; class QtColorPropertyManager* colorManager_{ nullptr }; diff --git a/src/ui/PropertyBrowser/qtmodelattribute.cpp b/src/ui/PropertyBrowser/qtmodelattribute.cpp index b114f483..0e14ff4a 100644 --- a/src/ui/PropertyBrowser/qtmodelattribute.cpp +++ b/src/ui/PropertyBrowser/qtmodelattribute.cpp @@ -1,16 +1,18 @@ #include "qtmodelattribute.h" QModelAttbute::QModelAttbute(QString name, QString discription, - bool inflow, float innerBottomElevation) + bool inflow, float innerBottomElevation, bool visible) : name_(name) , description_(discription) , inflow_(inflow) - , innerBottomElevation_(innerBottomElevation) { + , innerBottomElevation_(innerBottomElevation) + , visible_(visible) { } bool QModelAttbute::operator==(const QModelAttbute& other) { return name_ == other.name_ && description_ == other.description_ && - inflow_ == other.inflow_ && innerBottomElevation_ == other.innerBottomElevation_; + inflow_ == other.inflow_ && innerBottomElevation_ == other.innerBottomElevation_ && + visible_ == other.visible_; } void QModelAttbute::SetName(const QString& name) { @@ -29,3 +31,6 @@ void QModelAttbute::SetInnerBottomElevation(float v) { innerBottomElevation_ = v; } +void QModelAttbute::SetVisible(bool v) { + visible_ = v; +} \ No newline at end of file diff --git a/src/ui/PropertyBrowser/qtmodelattribute.h b/src/ui/PropertyBrowser/qtmodelattribute.h index a15bfa7e..cd7076e7 100644 --- a/src/ui/PropertyBrowser/qtmodelattribute.h +++ b/src/ui/PropertyBrowser/qtmodelattribute.h @@ -45,7 +45,7 @@ class QModelAttbute { public: QModelAttbute() = default; - QModelAttbute(QString name, QString discription, bool inflow, float innerBottomElevation); + QModelAttbute(QString name, QString discription, bool inflow, float innerBottomElevation, bool visible); ~QModelAttbute() = default; bool operator== (const QModelAttbute& other); @@ -70,11 +70,17 @@ public: return innerBottomElevation_; } + void SetVisible(bool v); + bool IsVisible() const { + return visible_; + } + private: QString name_; QString description_; bool inflow_{ false }; float innerBottomElevation_{ 0.0f }; + bool visible_{ true }; }; //Q_DECLARE_SHARED(QModelAttbute) diff --git a/src/ui/PropertyBrowser/qtpropertymanager.cpp b/src/ui/PropertyBrowser/qtpropertymanager.cpp index 7f18268e..c2948518 100644 --- a/src/ui/PropertyBrowser/qtpropertymanager.cpp +++ b/src/ui/PropertyBrowser/qtpropertymanager.cpp @@ -7645,7 +7645,7 @@ class QtModelBasePropertyManagerPrivate { public: void slotStringChanged(QtProperty* property, QString value); - void slotStringChanged(QtProperty* property, bool value); + void slotBoolChanged(QtProperty* property, bool value); void slotStringChanged(QtProperty* property, double value); void slotPropertyDestroyed(QtProperty* property); @@ -7662,12 +7662,13 @@ public: QMap m_properyToDescription; QMap m_properyToInflow; QMap m_properyToInnerBottomElevation; + QMap m_properyToVisible; QMap m_nameToPropery; QMap m_descriptionToPropery; QMap m_inflowToPropery; QMap m_InnerBottomElevationToPropery; - + QMap m_visibleToPropery; }; void QtModelBasePropertyManagerPrivate::slotStringChanged(QtProperty* property, QString value) { @@ -7678,7 +7679,7 @@ void QtModelBasePropertyManagerPrivate::slotStringChanged(QtProperty* property, } } -void QtModelBasePropertyManagerPrivate::slotStringChanged(QtProperty* property, bool value) { +void QtModelBasePropertyManagerPrivate::slotBoolChanged(QtProperty* property, bool value) { if (QtProperty* prop = m_properyToInflow.value(property, 0)) { QModelAttbute c = m_values[prop]; c.EnableInflow(value); @@ -7705,7 +7706,7 @@ QtModelBasePropertyManager::QtModelBasePropertyManager(QObject* parent) d_ptr->m_boolPropertyManager = new QtBoolPropertyManager(this); connect(d_ptr->m_boolPropertyManager, SIGNAL(valueChanged(QtProperty*, bool)), - this, SLOT(slotStringChanged(QtProperty*, bool))); + this, SLOT(slotBoolChanged(QtProperty*, bool))); d_ptr->m_deoubleProperyManager = new QtDoublePropertyManager(this); connect(d_ptr->m_deoubleProperyManager, SIGNAL(valueChanged(QtProperty*, double)), @@ -7787,7 +7788,8 @@ void QtModelBasePropertyManager::setValue(QtProperty* property, const QModelAttb d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToDescription[property], value.GetDescription()); d_ptr->m_boolPropertyManager->setValue(d_ptr->m_properyToInflow[property], value.IsEnableInfow()); d_ptr->m_deoubleProperyManager->setValue(d_ptr->m_properyToInnerBottomElevation[property], value.GetInnerBottomElevation()); - + d_ptr->m_boolPropertyManager->setValue(d_ptr->m_properyToVisible[property], value.IsVisible()); + emit propertyChanged(property); emit valueChanged(property, value); } @@ -7822,10 +7824,17 @@ void QtModelBasePropertyManager::initializeProperty(QtProperty* property) { prop = d_ptr->m_deoubleProperyManager->addProperty(); prop->setPropertyName(tr("InnerBottomElevation")); - d_ptr->m_boolPropertyManager->setValueOnly(prop, val.GetInnerBottomElevation()); + d_ptr->m_deoubleProperyManager->setValueOnly(prop, val.GetInnerBottomElevation()); d_ptr->m_properyToInnerBottomElevation[property] = prop; d_ptr->m_InnerBottomElevationToPropery[prop] = property; property->addSubProperty(prop); + + prop = d_ptr->m_boolPropertyManager->addProperty(); + prop->setPropertyName(tr("Visible")); + d_ptr->m_boolPropertyManager->setValueOnly(prop, val.IsVisible()); + d_ptr->m_properyToVisible[property] = prop; + d_ptr->m_visibleToPropery[prop] = property; + property->addSubProperty(prop); } /*! @@ -7859,6 +7868,13 @@ void QtModelBasePropertyManager::uninitializeProperty(QtProperty* property) { delete prop; } d_ptr->m_properyToInnerBottomElevation.remove(property); + + prop = d_ptr->m_visibleToPropery[property]; + if (prop) { + d_ptr->m_visibleToPropery.remove(prop); + delete prop; + } + d_ptr->m_properyToVisible.remove(property); } #pragma endregion @@ -8196,7 +8212,7 @@ public: void slotStringChanged(QtProperty* property, QString value); void slotTransfromChanged(QtProperty* property, QTransformAttribute value); - + void slotBoolChanged(QtProperty* property, bool value); void slotPropertyDestroyed(QtProperty* property); typedef QMap PropertyValueMap; @@ -8204,14 +8220,16 @@ public: QtStringPropertyManager* m_stringProperyManager; + QtBoolPropertyManager* m_boolProperyManager; QtTransfromPropertyManager* m_transfromPropertyManager; QMap m_properyToName; QMap m_properyTotrans; + QMap m_properyToVisible; QMap m_nameToPropery; QMap m_transToPropery; - + QMap m_visibleToPropery; }; void QtEntityPropertyManagerPrivate::slotStringChanged(QtProperty* property, QString value) { @@ -8222,6 +8240,15 @@ void QtEntityPropertyManagerPrivate::slotStringChanged(QtProperty* property, QSt } } +void QtEntityPropertyManagerPrivate::slotBoolChanged(QtProperty* property, bool value) { + + if (QtProperty* prop = m_properyToVisible.value(property, 0)) { + QEntityAttribute c = m_values[prop]; + c.SetVisible(value); + q_ptr->setValue(prop, c); + } +} + void QtEntityPropertyManagerPrivate::slotTransfromChanged(QtProperty* property, QTransformAttribute value) { if (QtProperty* prop = m_properyTotrans.value(property, 0)) { QEntityAttribute c = m_values[prop]; @@ -8237,6 +8264,9 @@ void QtEntityPropertyManagerPrivate::slotPropertyDestroyed(QtProperty* property) } else if (QtProperty* subProp = m_transToPropery.value(property, nullptr)) { m_transToPropery[subProp] = 0; m_transToPropery.remove(property); + } else if (QtProperty* subProp = m_visibleToPropery.value(property, nullptr)) { + m_visibleToPropery[subProp] = 0; + m_visibleToPropery.remove(property); } } @@ -8247,7 +8277,11 @@ QtEntityPropertyManager::QtEntityPropertyManager(QObject* parent) d_ptr->m_stringProperyManager = new QtStringPropertyManager(this); connect(d_ptr->m_stringProperyManager, SIGNAL(valueChanged(QtProperty*, QString)), this, SLOT(slotStringChanged(QtProperty*, QString))); - + + d_ptr->m_boolProperyManager = new QtBoolPropertyManager(this); + connect(d_ptr->m_boolProperyManager, SIGNAL(valueChanged(QtProperty*, bool)), + this, SLOT(slotBoolChanged(QtProperty*, bool))); + d_ptr->m_transfromPropertyManager = new QtTransfromPropertyManager(this); connect(d_ptr->m_transfromPropertyManager, SIGNAL(valueChanged(QtProperty*, QTransformAttribute)), this, SLOT(slotTransfromChanged(QtProperty*, QTransformAttribute))); @@ -8323,7 +8357,7 @@ void QtEntityPropertyManager::setValue(QtProperty* property, const QEntityAttrib d_ptr->m_stringProperyManager->setValue(d_ptr->m_properyToName[property], value.GetName()); d_ptr->m_transfromPropertyManager->setValue(d_ptr->m_properyTotrans[property], value.GetTransform()); - + d_ptr->m_boolProperyManager->setValue(d_ptr->m_properyToVisible[property], value.IsVisible()); emit propertyChanged(property); emit valueChanged(property, value); } @@ -8342,6 +8376,13 @@ void QtEntityPropertyManager::initializeProperty(QtProperty* property) { d_ptr->m_nameToPropery[prop] = property; property->addSubProperty(prop); + prop = d_ptr->m_boolProperyManager->addProperty(); + prop->setPropertyName(tr("Visible")); + d_ptr->m_boolProperyManager->setValueOnly(prop, val.IsVisible()); + d_ptr->m_properyToVisible[property] = prop; + d_ptr->m_visibleToPropery[prop] = property; + property->addSubProperty(prop); + prop = d_ptr->m_transfromPropertyManager->addProperty(); prop->setPropertyName(tr("Transform")); d_ptr->m_transfromPropertyManager->setValueOnly(prop, val.GetTransform()); @@ -8361,6 +8402,13 @@ void QtEntityPropertyManager::uninitializeProperty(QtProperty* property) { } d_ptr->m_properyToName.remove(property); + prop = d_ptr->m_visibleToPropery[property]; + if (prop) { + d_ptr->m_visibleToPropery.remove(prop); + delete prop; + } + d_ptr->m_properyToVisible.remove(property); + prop = d_ptr->m_transToPropery[property]; if (prop) { d_ptr->m_properyTotrans.remove(prop); diff --git a/src/ui/PropertyBrowser/qtworkspaceattribute.cpp b/src/ui/PropertyBrowser/qtworkspaceattribute.cpp index 2988312d..1b1ddc29 100644 --- a/src/ui/PropertyBrowser/qtworkspaceattribute.cpp +++ b/src/ui/PropertyBrowser/qtworkspaceattribute.cpp @@ -228,10 +228,11 @@ QTransformAttribute& QTransformAttribute::operator=(const QTransformAttribute& o QEntityAttribute::QEntityAttribute(class Entity* entity) : entity_(entity) { - if (nullptr == entity) { + if (nullptr == entity) { return; } transform_ = (new QTransformAttribute(entity->GetTransform())); + visible_ = entity->IsVisible(); } bool QEntityAttribute::operator==(const QEntityAttribute& other) { @@ -266,6 +267,19 @@ QTransformAttribute QEntityAttribute::GetTransform() const { return *transform_; } +void QEntityAttribute::SetVisible(bool v) { + visible_ = v; + if (nullptr == entity_) { + return; + } + + entity_->SetVisible(v); +} + +bool QEntityAttribute::IsVisible() const { + return visible_; +} + QMeshComponentAttribute::QMeshComponentAttribute(class MeshComponent* object) : object_(object) { } diff --git a/src/ui/PropertyBrowser/qtworkspaceattribute.h b/src/ui/PropertyBrowser/qtworkspaceattribute.h index 23863dcc..7cd45748 100644 --- a/src/ui/PropertyBrowser/qtworkspaceattribute.h +++ b/src/ui/PropertyBrowser/qtworkspaceattribute.h @@ -118,10 +118,13 @@ public: QTransformAttribute GetTransform() const; + void SetVisible(bool v); + bool IsVisible() const; private: class Entity* entity_{ nullptr }; QTransformAttribute* transform_{ nullptr }; + bool visible_{ true }; }; class QMeshComponentAttribute {