소스 검색

Parameter sucess

Willi Zschiebsch 4 년 전
부모
커밋
af4f46a34a
7개의 변경된 파일212개의 추가작업 그리고 65개의 파일을 삭제
  1. 5 0
      lib/include/IProcessor.h
  2. 1 0
      lib/include/Parameter.h
  3. 7 0
      lib/include/ProcessorBase.h
  4. 35 1
      lib/src/Connector.cpp
  5. 8 0
      lib/src/ModuleBase.cpp
  6. 17 17
      lib/src/Parameter.cpp
  7. 139 47
      lib/src/ProcessorBase.cpp

+ 5 - 0
lib/include/IProcessor.h

@@ -13,6 +13,11 @@ namespace mdd
         virtual std::string addModule(std::shared_ptr<IModule> module) = 0;
         virtual void  removeModule(std::shared_ptr<IModule> module) = 0;
 
+        virtual json addInput(std::shared_ptr<IInput> input) = 0;
+        virtual json removeInput(std::shared_ptr<IInput> input) = 0;
+        virtual json addOutput(std::shared_ptr<IOutput> output) = 0;
+        virtual json removeOutput(std::shared_ptr<IOutput> output) = 0;
+
         virtual std::vector<std::shared_ptr<Parameter>>& getInputParams() = 0;
         virtual std::vector<std::shared_ptr<Parameter>>& getOutputParams() = 0;
 

+ 1 - 0
lib/include/Parameter.h

@@ -10,6 +10,7 @@ namespace mdd {
         Parameter();
         state update() override;
         std::string setName(const std::string& type);
+        std::string setKey(const std::string& type);
         std::string setAppendix(int appendix) override;
     };
 }

+ 7 - 0
lib/include/ProcessorBase.h

@@ -16,6 +16,8 @@ namespace mdd {
         int _appendix = 0;
 
         unsigned int module_counter = 0;
+        unsigned int input_counter = 0;
+        unsigned int output_counter = 0;
 
     protected:
         json _base_config;
@@ -46,6 +48,11 @@ namespace mdd {
         std::string addModule(std::shared_ptr<IModule> module) override ;
         void removeModule(std::shared_ptr<IModule> module) override;
 
+        json addInput(std::shared_ptr<IInput> input) override;
+        json removeInput(std::shared_ptr<IInput> input) override;
+        json addOutput(std::shared_ptr<IOutput> output) override;
+        json removeOutput(std::shared_ptr<IOutput> output) override;
+
         std::vector<std::shared_ptr<Parameter>>& getInputParams() override;
         std::vector<std::shared_ptr<Parameter>>& getOutputParams() override;
 

+ 35 - 1
lib/src/Connector.cpp

@@ -84,6 +84,40 @@ namespace mdd {
 				}
 			}
 		}
+		else if (*jobj_typ == "input") {
+			IModule::Ptr module_in_ptr = _root->getModule(*jobj);
+			if (module_in_ptr != nullptr) {
+				IInput::Ptr in_ptr = nullptr;
+				std::string id = (*jobj)["key"].get<std::string>() + std::to_string((*jobj)["appendix"].get<int>());
+				for (size_t i = 0; i < module_in_ptr->getNumInputs(); i++)
+				{
+					auto in = module_in_ptr->getInput(i);
+					if (in->getID() == id)
+					{
+						in_ptr = in;
+						break;
+					}
+				}
+				return proc_ptr->addInput(in_ptr);
+			}
+		}
+		else if (*jobj_typ == "output") {
+			IModule::Ptr module_out_ptr = _root->getModule(*jobj);
+			if (module_out_ptr != nullptr) {
+				IOutput::Ptr out_ptr = nullptr;
+				std::string id = (*jobj)["key"].get<std::string>() + std::to_string((*jobj)["appendix"].get<int>());
+				for (size_t i = 0; i < module_out_ptr->getNumOutputs(); i++)
+				{
+					auto out = module_out_ptr->getOutput(i);
+					if (out->getID() == id)
+					{
+						out_ptr = out;
+						break;
+					}
+				}
+				return proc_ptr->addOutput(out_ptr);
+			}
+		}
 		else {
 			return ret;
 		}
@@ -361,7 +395,7 @@ namespace mdd {
 		
 		json ret;
 		ret["operation"] = "state";
-		ret["args"] = encode();
+		ret["args"].push_back(encode());
 		return ret;
 	}
 

+ 8 - 0
lib/src/ModuleBase.cpp

@@ -109,6 +109,14 @@ namespace mdd {
         if (jit != jconfig.end()) {
             res = configureChild(jit.value());
         }
+        jit = jconfig.find("appendix");
+        if (jit != jconfig.end()) {
+            setAppendix(jit.value()["value"].get<int>());
+        }
+        jit = jconfig.find("key");
+        if (jit != jconfig.end()) {
+            key = jit.value()["value"].get<std::string>();
+        }
         return res;
     }
    

+ 17 - 17
lib/src/Parameter.cpp

@@ -3,13 +3,16 @@
 namespace mdd {
     Parameter::Parameter()
         : ModuleBase(R"JSON(
-        [{
-            "name":"appendix",
-            "value":0
-        }])JSON")
+        {
+        "configure":{},
+        "GUI":{
+            "name":{"value":"Parameter"},
+            "color":{"value":"#b91203"}
+        }
+        })JSON")
     {
-        inputs.push_back(std::make_shared<Input>("Value", 0));
-        outputs.push_back(std::make_shared<Output>("Value", 0));
+        inputs.push_back(std::make_shared<Input>("Value",0));
+        outputs.push_back(std::make_shared<Output>("Value",0));
         
         key = "Parameter";
         setName(key);
@@ -20,11 +23,17 @@ namespace mdd {
     }
 
     std::string Parameter::setName(const std::string& name) {
-        //inputs[0]->setName(name);
+        _base_config["GUI"]["name"]["value"] = name;
+        inputs[0]->setName(name);
         outputs[0]->setName(name);
         return name;
     }
 
+    std::string Parameter::setKey(const std::string& type) {
+        key = type;
+        return key;
+    }
+
     std::string Parameter::setAppendix(int appendix)
     {
         inputs[0]->setAppendix(appendix);
@@ -34,15 +43,6 @@ namespace mdd {
 
     bool Parameter::configureChild(const json& config)
     {
-        auto jit = config.find("name");
-        if (jit != config.end())
-        {
-            if (jit.value().get<std::string>() == "appendix")
-            {
-                setAppendix(jit.value()["value"].get<int>());
-                _base_config["configure"]["appendix"]["value"] = getAppendix();
-            }
-        }
-        return false;
+        return true;
     }
 }

+ 139 - 47
lib/src/ProcessorBase.cpp

@@ -160,6 +160,47 @@ namespace mdd{
         }
     }
 
+    json ProcessorBase::addInput(std::shared_ptr<IInput> input) {
+        auto param_ptr = std::make_shared<Parameter>();
+        param_ptr->setName(input->getName());
+        param_ptr->getOutput(0)->connect(input);
+        getInputParams().push_back(param_ptr);
+        param_ptr->setKey("Parameter/Input");
+        param_ptr->setAppendix(input_counter++);
+        param_ptr->setParent(shared_from_this());
+        json ret;
+        ret["operation"] = "change";
+        json jargs;
+        jargs["subject"] = getIdentifier();
+        jargs["object"] = dump();
+        ret["args"] = jargs;
+        return ret;
+    }
+    json ProcessorBase::removeInput(std::shared_ptr<IInput> input) {
+        json ret;
+        return ret;
+    }
+    json ProcessorBase::addOutput(std::shared_ptr<IOutput> output) {
+        auto param_ptr = std::make_shared<Parameter>();
+        param_ptr->setName(output->getName());
+        param_ptr->getInput(0)->connect(output);
+        getOutputParams().push_back(param_ptr);
+        param_ptr->setKey("Parameter/Output");
+        param_ptr->setAppendix(output_counter++);
+        param_ptr->setParent(shared_from_this());
+        json ret;
+        ret["operation"] = "change";
+        json jargs;
+        jargs["subject"] = getIdentifier();
+        jargs["object"] = dump();
+        ret["args"] = jargs;
+        return ret;
+    }
+    json ProcessorBase::removeOutput(std::shared_ptr<IOutput> output) {
+        json ret;
+        return ret;
+    }
+
     std::vector<std::shared_ptr<Parameter>>& ProcessorBase::getInputParams() {
         return inputs;
     }
@@ -264,29 +305,33 @@ namespace mdd{
     }
 
     void ProcessorBase::load(const json& j) {
-        if (j.contains("ID"))
+        auto jit = j.find("ID");
+        if (jit != j.end())
         {
-            setAppendix(j["ID"]["appendix"].get<int>());
+            setAppendix((*jit)["appendix"].get<int>());
             j["ID"]["type"];
 
         }
-        if (j.contains("key"))
+        jit = j.find("key");
+        if (jit != j.end())
         {
 
         }
-        if (j.contains("type"))
+        jit = j.find("type");
+        if (jit != j.end())
         {
 
         }
-        if (j.contains("configure"))
+        jit = j.find("configure");
+        if (jit != j.end())
         {
 
         }
-
-        if (j.contains("modules"))
+        jit = j.find("modules");
+        if (jit != j.end())
         {
             Registration regi = Registration();
-            for (json jmodule : j["modules"])
+            for (json jmodule : *jit)
             {
                 if (jmodule["type"].get<std::string>() == "module")
                 {
@@ -304,27 +349,37 @@ namespace mdd{
             }
         }
 
-        if (j.contains("inputs"))
+        jit = j.find("params");
+        if (jit != j.end())
         {
-            const size_t start_counter = processor_inputs.size();
-            for (size_t i = start_counter; i < j["inputs"].size(); i++)
+            auto jit_params = jit->find("inputs");
+            if (jit_params != jit->end())
             {
-
+                const size_t start_counter = processor_outputs.size();
+                for (size_t i = start_counter; i < (*jit_params).size(); i++)
+                {
+                    inputs.push_back(std::make_shared<Parameter>());
+                    inputs.back()->load((*jit_params)[i]);
+                }
             }
-        }
 
-        if (j.contains("outputs"))
-        {
-            const size_t start_counter = processor_outputs.size();
-            for (size_t i = start_counter; i < j["outputs"].size(); i++)
+            jit_params = jit->find("outputs");
+            if (jit_params != jit->end())
             {
-
+                const size_t start_counter = processor_inputs.size();
+                for (size_t i = start_counter; i < (*jit_params).size(); i++)
+                {
+                    outputs.push_back(std::make_shared<Parameter>());
+                    outputs.back()->load((*jit_params)[i]);
+                }
             }
         }
+        
 
-        if (j.contains("connections"))
+        jit = j.find("connections");
+        if (jit != j.end())
         {
-            for(json jcon : j["connections"])
+            for(json jcon : *jit)
             {
                 json jout = jcon["output"];
                 IModule::Ptr module_out_ptr = getModule(jout);
@@ -366,6 +421,16 @@ namespace mdd{
         {
             modules[i]->setAppendix(i);
         }
+        for (int i = 0; i < inputs.size(); ++i)
+        {
+            inputs[i]->setAppendix(i);
+        }
+        input_counter = inputs.size();
+        for (int i = 0; i < outputs.size(); ++i)
+        {
+            outputs[i]->setAppendix(i);
+        }
+        output_counter = outputs.size();
     }
 
     json ProcessorBase::dump() {
@@ -376,48 +441,55 @@ namespace mdd{
 
         ret["params"];
         ret["params"]["inputs"];
+        for (auto& out : processor_outputs)
+        {
+            out->setParent(shared_from_this());
+            ret["outputs"].push_back(out->dump());
+
+            json param;
+            param["GUI"] = getConfiguration()["GUI"];
+            param["ID"] = out->getIdentifier();
+            param["ID"]["type"] = "module";
+            param["type"] = "module";
+            param["key"] = "Input";
+            param["GUI"]["name"]["value"] = param["GUI"]["name"]["value"].get<std::string>() + "/" + out->getName();
+            param["outputs"].push_back(out->dump());
+            ret["params"]["inputs"].push_back(param);
+        }
         for (size_t i = 0; i < inputs.size(); i++)
         {
             if (auto in_ptr = inputs[i])
             {
-                json sub;
-                sub["type"] = in_ptr->getType();
-                sub["appendix"] = in_ptr->getAppendix();
-                ret["params"]["inputs"].push_back(sub);
+                ret["inputs"].push_back(in_ptr->getInput(0)->dump());
+                ret["params"]["inputs"].push_back(in_ptr->dump());
             }
         }
 
         ret["params"]["outputs"];
-        for (size_t i = 0; i < outputs.size(); i++)
-        {
-            if (auto out_ptr = outputs[i])
-            {
-                json sub;
-                sub["type"] = out_ptr->getType();
-                sub["appendix"] = out_ptr->getAppendix();
-                ret["params"]["outputs"].push_back(sub);
-            }
-        }
-
         for (auto& in : processor_inputs)
         {
             in->setParent(shared_from_this());
             ret["inputs"].push_back(in->dump());
-        }
-        for (auto& in : inputs)
-        {
-            ret["inputs"].push_back(in->getInput(0)->dump());
-        }
 
-        for (auto& out : processor_outputs)
-        {
-            out->setParent(shared_from_this());
-            ret["outputs"].push_back(out->dump());
+            json param;
+            param["GUI"] = getConfiguration()["GUI"];
+            param["ID"] = in->getIdentifier();
+            param["ID"]["type"] = "module";
+            param["type"] = "module";
+            param["key"] = "Output";
+            param["GUI"]["name"]["value"] = param["GUI"]["name"]["value"].get<std::string>() + "/" + in->getName();
+            param["inputs"].push_back(in->dump());
+            ret["params"]["outputs"].push_back(param);
         }
-        for (auto& out : outputs)
+        for (size_t i = 0; i < outputs.size(); i++)
         {
-            ret["outputs"].push_back(out->getInput(0)->dump());
+            if (auto out_ptr = outputs[i])
+            {
+                ret["outputs"].push_back(out_ptr->getOutput(0)->dump());
+                ret["params"]["outputs"].push_back(out_ptr->dump());
+            }
         }
+
         for (auto& mod : modules)
         {
             if (auto module_ptr = mod)
@@ -453,6 +525,26 @@ namespace mdd{
                 }
             }
         }
+        for (auto& mod : inputs)
+        {
+            if (auto module_ptr = mod)
+            {
+                for (size_t j = 0; j < module_ptr->getNumOutputs(); j++)
+                {
+                    auto input_connections = module_ptr->getOutput(j)->getConnections();
+                    if (!input_connections.empty())
+                    {
+                        json connect;
+                        connect["output"] = module_ptr->getOutput(j)->getIdentifier();
+                        for (size_t k = 0; k < input_connections.size(); k++)
+                        {
+                            connect["inputs"].push_back(input_connections[k]->getIdentifier());
+                        }
+                        ret["connections"].push_back(connect);
+                    }
+                }
+            }
+        }
         return ret;
     }
 
@@ -628,7 +720,7 @@ namespace mdd{
         }
         std::string sid;
         ++same_counter;
-        if (same_counter + final_size == jid_pref->size())
+        if (same_counter == jid_pref->size() && final_size == 0)
         {
             sid = jid["key"].get<std::string>() + std::to_string(jid["appendix"].get<int>());
         }