Scicos: speedup model transformation
[scilab.git] / scilab / modules / scicos / src / cpp / view_scilab / Adapters.cpp
index bddd91a..97f9a6d 100644 (file)
@@ -1,20 +1,23 @@
 /*
  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- *  Copyright (C) 2014-2014 - Scilab Enterprises - Clement DAVID
+ *  Copyright (C) 2014-2016 - Scilab Enterprises - Clement DAVID
  *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
  *
  */
 
+#include "../../../includes/view_scilab/Adapters.hxx"
+
 #include <string>
 #include <algorithm>
 
-#include "Adapters.hxx"
-
 #include "BlockAdapter.hxx"
 #include "CprAdapter.hxx"
 #include "DiagramAdapter.hxx"
@@ -22,6 +25,7 @@
 #include "LinkAdapter.hxx"
 #include "ModelAdapter.hxx"
 #include "ParamsAdapter.hxx"
+#include "ScsAdapter.hxx"
 #include "StateAdapter.hxx"
 #include "TextAdapter.hxx"
 
@@ -53,6 +57,7 @@ Adapters::Adapters()
     adapters.push_back(adapter_t(view_scilab::LinkAdapter::getSharedTypeStr(), LINK_ADAPTER));
     adapters.push_back(adapter_t(view_scilab::ModelAdapter::getSharedTypeStr(), MODEL_ADAPTER));
     adapters.push_back(adapter_t(view_scilab::ParamsAdapter::getSharedTypeStr(), PARAMS_ADAPTER));
+    adapters.push_back(adapter_t(view_scilab::ScsAdapter::getSharedTypeStr(), SCS_ADAPTER));
     adapters.push_back(adapter_t(view_scilab::StateAdapter::getSharedTypeStr(), STATE_ADAPTER));
     adapters.push_back(adapter_t(view_scilab::TextAdapter::getSharedTypeStr(), TEXT_ADAPTER));
 
@@ -74,5 +79,75 @@ Adapters::adapters_index_t Adapters::lookup_by_typename(const std::wstring& name
     return INVALID_ADAPTER;
 }
 
+std::wstring Adapters::get_typename(Adapters::adapters_index_t kind)
+{
+    for (auto it : adapters)
+    {
+        if (it.kind == kind)
+        {
+            return it.name;
+        }
+    }
+
+    return L"";
+}
+
+model::BaseObject* Adapters::descriptor(types::InternalType* v)
+{
+    const std::wstring& name = v->getShortTypeStr();
+    adapters_t::iterator it = std::lower_bound(adapters.begin(), adapters.end(), name);
+    if (v->isUserType() && it != adapters.end() && !(name < it->name))
+    {
+        return descriptor(it->kind, v);
+    }
+    return nullptr;
+}
+
+model::BaseObject* Adapters::descriptor(adapters_index_t index, types::InternalType* v)
+{
+    switch (index)
+    {
+        case BLOCK_ADAPTER:
+            return v->getAs<view_scilab::BlockAdapter>()->getAdaptee();
+        case CPR_ADAPTER:
+            return v->getAs<view_scilab::CprAdapter>()->getAdaptee();
+        case DIAGRAM_ADAPTER:
+            return v->getAs<view_scilab::DiagramAdapter>()->getAdaptee();
+        case GRAPHIC_ADAPTER:
+            return v->getAs<view_scilab::GraphicsAdapter>()->getAdaptee();
+        case LINK_ADAPTER:
+            return v->getAs<view_scilab::LinkAdapter>()->getAdaptee();
+        case MODEL_ADAPTER:
+            return v->getAs<view_scilab::ModelAdapter>()->getAdaptee();
+        case PARAMS_ADAPTER:
+            return v->getAs<view_scilab::ParamsAdapter>()->getAdaptee();
+        case SCS_ADAPTER:
+            return v->getAs<view_scilab::ScsAdapter>()->getAdaptee();
+        case STATE_ADAPTER:
+            return v->getAs<view_scilab::StateAdapter>()->getAdaptee();
+        case TEXT_ADAPTER:
+            return v->getAs<view_scilab::TextAdapter>()->getAdaptee();
+        default:
+            return nullptr;
+    }
+}
+
+types::InternalType* Adapters::allocate_view(ScicosID id, kind_t kind)
+{
+    Controller controller;
+
+    switch (kind)
+    {
+        case BLOCK:
+            return new view_scilab::BlockAdapter(controller, controller.getBaseObject<model::Block>(id));
+        case LINK:
+            return new view_scilab::LinkAdapter(controller, controller.getBaseObject<model::Link>(id));
+        case DIAGRAM:
+            return new view_scilab::DiagramAdapter(controller, controller.getBaseObject<model::Diagram>(id));
+        default:
+            return nullptr;
+    }
+}
+
 } /* namespace view_scilab */
 } /* namespace org_scilab_modules_scicos */