Przeglądaj źródła

ENH: some initial code for the app logic example

ivowolf 14 lat temu
rodzic
commit
a022f630f5

+ 2 - 0
Plugins/org.commontk.example.dicomapp/CMakeLists.txt

@@ -4,11 +4,13 @@ SET(PLUGIN_export_directive "org_commontk_example_dicomapp_EXPORT")
 
 SET(PLUGIN_SRCS
   ctkExampleDicomAppPlugin.cpp
+  ctkExampleDicomAppLogic.cpp
 )
 
 # Files which should be processed by Qts moc
 SET(PLUGIN_MOC_SRCS
   ctkExampleDicomAppPlugin_p.h
+  ctkExampleDicomAppLogic_p.h
 )
 
 # Qt Designer files which should be processed by Qts uic

+ 57 - 0
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppLogic.cpp

@@ -0,0 +1,57 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#include "ctkExampleDicomAppLogic_p.h"
+#include <QtPlugin>
+#include <QRect>
+
+ctkExampleDicomAppLogic::ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface>* host)
+  : host(host)
+{
+}
+
+ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
+{
+  delete host;
+}
+
+ctkDicomWG23::State ctkExampleDicomAppLogic::getState()
+{
+  return ctkDicomWG23::IDLE;
+}
+
+bool ctkExampleDicomAppLogic::setState(ctkDicomWG23::State newState)
+{
+  qDebug() << "setState called";
+  return false;
+}
+
+bool ctkExampleDicomAppLogic::bringToFront(const QRect& requestedScreenArea)
+{
+  return false;
+}
+
+void ctkExampleDicomAppLogic::do_something()
+{
+  QRect preferred;
+  QRect rect = host->call()->getAvailableScreen(preferred);
+}

+ 76 - 0
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppLogic_p.h

@@ -0,0 +1,76 @@
+/*=============================================================================
+
+  Library: CTK
+
+  Copyright (c) 2010 German Cancer Research Center,
+    Division of Medical and Biological Informatics
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=============================================================================*/
+
+
+#ifndef CTKEXAMPLEDICOMAPPLOGIC_P_H
+#define CTKEXAMPLEDICOMAPPLOGIC_P_H
+
+#include <ctkPluginActivator.h>
+#include <ctkDicomAppInterface.h>
+#include <ctkDicomHostInterface.h>
+
+template <class TServiceType>
+class ServiceAccessor {
+public:
+  ServiceAccessor(ctkPluginContext* context, const QString& clazz) : context(context), clazz(clazz)
+  {
+  }
+  TServiceType* call()
+  {
+    ctkServiceReference* serviceRef = context->getServiceReference(clazz);
+    if (!serviceRef)
+    {
+      // this will change after merging changes from branch plugin_framework
+      throw std::runtime_error("No Dicom Host Service found");
+    }
+    return qobject_cast<TServiceType*>(context->getService(serviceRef));
+  }
+private:
+  ctkPluginContext* context;
+  const QString& clazz;
+};
+
+
+class ctkExampleDicomAppLogic :
+  public ctkDicomAppInterface
+{
+  Q_OBJECT
+
+public:
+
+  ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface>* host);
+  ~ctkExampleDicomAppLogic();
+
+  // ctkDicomAppInterface
+  ctkDicomWG23::State getState();
+  bool setState(ctkDicomWG23::State newState);
+  bool bringToFront(const QRect& requestedScreenArea);
+
+  // ctkDicomExchangeInterface
+
+  // some logic
+  void do_something();
+private:
+  ServiceAccessor<ctkDicomHostInterface>* host;
+
+}; // ctkExampleDicomAppLogic
+
+#endif // ctkExampleDicomAppLogic_P_H

+ 14 - 0
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppPlugin.cpp

@@ -21,7 +21,10 @@
 
 
 #include "ctkExampleDicomAppPlugin_p.h"
+#include "ctkExampleDicomAppLogic_p.h"
 #include <QtPlugin>
+#include <QStringList.h>
+#include <QString.h>
 
 ctkExampleDicomAppPlugin* ctkExampleDicomAppPlugin::instance = 0;
 
@@ -39,6 +42,17 @@ void ctkExampleDicomAppPlugin::start(ctkPluginContext* context)
 {
   instance = this;
   this->context = context;
+  context->registerService(QStringList("ctkDicomAppInterface"), 
+    new ctkExampleDicomAppLogic(new ServiceAccessor<ctkDicomHostInterface>(context,"ctkDicomHostInterface")));
+
+  //ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomHostInterface");
+  //if (!serviceRef)
+  //{
+  //  // this will change after merging changes from branch plugin_framework
+  //  throw std::runtime_error("No Dicom Host Service found");
+  //}
+  //ctkDicomHostInterface*
+  //  serviceBinding = qobject_cast<ctkDicomHostInterface*>(context->getService(serviceRef));
 }
 
 void ctkExampleDicomAppPlugin::stop(ctkPluginContext* context)