|
| 1 | +// |
| 2 | +// Copyright Copyright 2009-2025, AMT – The Association For Manufacturing Technology (“AMT”) |
| 3 | +// All rights reserved. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | +// |
| 17 | + |
| 18 | +#include "process.hpp" |
| 19 | + |
| 20 | +#include "target.hpp" |
| 21 | + |
| 22 | +using namespace std; |
| 23 | + |
| 24 | +namespace mtconnect { |
| 25 | + using namespace entity; |
| 26 | + namespace asset { |
| 27 | + FactoryPtr ProcessArchetype::getFactory() |
| 28 | + { |
| 29 | + static FactoryPtr factory; |
| 30 | + if (!factory) |
| 31 | + { |
| 32 | + auto activity = |
| 33 | + make_shared<Factory>(Requirements {{"sequence", ValueType::INTEGER, false}, |
| 34 | + {"activityId", true}, |
| 35 | + {"precedence", ValueType::INTEGER, false}, |
| 36 | + {"optional", ValueType::BOOL, false}, |
| 37 | + {"Description", false}}); |
| 38 | + |
| 39 | + auto activityGroup = make_shared<Factory>(Requirements { |
| 40 | + {"activityGroupId", true}, |
| 41 | + {"name", false}, |
| 42 | + {"Activity", ValueType::ENTITY, activity, 1, entity::Requirement::Infinite}, |
| 43 | + }); |
| 44 | + |
| 45 | + auto activityGroups = make_shared<Factory>(Requirements { |
| 46 | + {"ActivityGroup", ValueType::ENTITY, activityGroup, 1, entity::Requirement::Infinite}}); |
| 47 | + |
| 48 | + auto processStep = make_shared<Factory>( |
| 49 | + Requirements {{{"stepId", true}, |
| 50 | + {"optional", ValueType::BOOL, false}, |
| 51 | + {"sequence", ValueType::INTEGER, false}, |
| 52 | + {"Description", false}, |
| 53 | + {"StartTime", ValueType::TIMESTAMP, false}, |
| 54 | + {"Duration", ValueType::DOUBLE, false}, |
| 55 | + {"Targets", ValueType::ENTITY_LIST, Target::getTargetsFactory(), false}, |
| 56 | + {"ActivityGroups", ValueType::ENTITY_LIST, activityGroups, false}}}); |
| 57 | + processStep->setOrder( |
| 58 | + {"Description", "StartTime", "Duration", "Targets", "ActivityGroups"}); |
| 59 | + |
| 60 | + auto routing = make_shared<Factory>(Requirements { |
| 61 | + {"precedence", ValueType::INTEGER, true}, |
| 62 | + {"routingId", true}, |
| 63 | + {"ProcessStep", ValueType::ENTITY, processStep, 1, entity::Requirement::Infinite}, |
| 64 | + }); |
| 65 | + |
| 66 | + auto routings = make_shared<Factory>(Requirements { |
| 67 | + {"Routing", ValueType::ENTITY, routing, 1, entity::Requirement::Infinite}}); |
| 68 | + |
| 69 | + factory = make_shared<Factory>(*Asset::getFactory()); |
| 70 | + factory->addRequirements({ |
| 71 | + {"revision", true}, |
| 72 | + {"Targets", ValueType::ENTITY_LIST, Target::getTargetsFactory(), false}, |
| 73 | + {"Routings", ValueType::ENTITY_LIST, routings, true}, |
| 74 | + }); |
| 75 | + factory->setOrder({"Configuration", "Routings", "Targets"}); |
| 76 | + } |
| 77 | + return factory; |
| 78 | + } |
| 79 | + |
| 80 | + void ProcessArchetype::registerAsset() |
| 81 | + { |
| 82 | + static bool once {true}; |
| 83 | + if (once) |
| 84 | + { |
| 85 | + Asset::registerAssetType("ProcessArchetype", getFactory()); |
| 86 | + once = false; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + FactoryPtr Process::getFactory() |
| 91 | + { |
| 92 | + static FactoryPtr factory; |
| 93 | + if (!factory) |
| 94 | + { |
| 95 | + factory = ProcessArchetype::getFactory()->deepCopy(); |
| 96 | + auto routings = factory->getRequirement("Routings"); |
| 97 | + auto routing = routings->getFactory()->getRequirement("Routing"); |
| 98 | + routing->setMultiplicity(1, 1); |
| 99 | + } |
| 100 | + return factory; |
| 101 | + } |
| 102 | + |
| 103 | + void Process::registerAsset() |
| 104 | + { |
| 105 | + static bool once {true}; |
| 106 | + if (once) |
| 107 | + { |
| 108 | + Asset::registerAssetType("Process", getFactory()); |
| 109 | + once = false; |
| 110 | + } |
| 111 | + } |
| 112 | + } // namespace asset |
| 113 | +} // namespace mtconnect |
0 commit comments