Developer documentation | Axl-2.5.1

axlLineCreator.cpp
Go to the documentation of this file.
1 /* axlLineCreator.cpp ---
2  *
3  * Author: Anais Ducoffe
4  * Copyright (C) 2012, Anais Ducoffe, INRIA.
5  */
6 
7 /* Commentary:
8  */
9 
10 /* Change log:
11  *
12  */
13 
14 #include "axlLineCreator.h"
15 #include <axlCore/axlPoint.h>
16 #include <axlCore/axlLine.h>
17 #include <axlCore/axlDataDynamic.h>
19 
20 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
21 
25 
26 class axlLineCreatorPrivate {
27 
28 public:
29  axlPoint *point1;
30  axlPoint *point2;
31  axlLine *output;
32 };
33 
37 axlLineCreator::axlLineCreator(QObject *parent ) : axlAbstractCreatorProcess(), d(new axlLineCreatorPrivate) {
38  d->point1 = NULL;
39  d->point2 = NULL;
40  d->output = NULL;
41 
42  dtkAbstractProcessFactory::instance()->registerProcessType("axlLineCreator", createaxlLineCreator);
43 }
44 
45 axlLineCreator::axlLineCreator(const axlLineCreator *other, QObject *parent) : axlAbstractCreatorProcess(), d(new axlLineCreatorPrivate) {
46  d->point1 = dynamic_cast<axlPoint *>(other->getInput(0));
47  d->point2 = dynamic_cast<axlPoint *>(other->getInput(1));
48  d->output = NULL;//dynamic_cast<axlLine *>(other->output());
49 }
50 
52  delete d;
53  d = NULL;
54 }
55 
57  if (channel == 0) {
58  return d->point1;
59  } else {
60  return d->point2;
61  }
62 }
63 
65  return false;
66 }
67 
68 
69 dtkAbstractData *axlLineCreator::output(void) {
70  return d->output;
71 }
72 
73 dtkAbstractData *axlLineCreator::output(int channel) {
74  return d->output;
75 }
76 
77 void axlLineCreator::setInput(dtkAbstractData *newData, int channel) {
78  if (dynamic_cast<axlAbstractData *>(newData)) {
79  axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(newData);
80  if (dynamic_cast<axlPoint *>(axlData)) {
81  axlPoint *point = dynamic_cast<axlPoint *>(axlData);
82  if (channel == 0) {
83  d->point1 = point;
84  } else {
85  d->point2 = point;
86  }
87  }
88  }
89 }
90 
92  axlLine *newLine = NULL;
93  if (d->output == NULL) {
94  if (d->point1 && d->point2) {
95  newLine = new axlLine(d->point1, d->point2);
96  d->output = newLine;
97  return 1;
98  } else {
99  return 0;
100  }
101  } else {
102  if (d->point1 && d->point2) {
103  d->output->onFirstPointChanged(d->point1);
104  d->output->onSecondPointChanged(d->point2);
105  return 1;
106  } else {
107  return 0;
108  }
109  }
110 }
111 
112 QString axlLineCreator::description(void) const {
113  return "create a line with two points";
114 }
115 
116 
117 QString axlLineCreator::identifier(void) const {
118  return "axlLineCreator";
119 }
120 
121 dtkAbstractProcess *createaxlLineCreator(void) {
122  return new axlLineCreator;
123 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
Class axlLine defines 3D lines.
Definition: axlLine.h:35
virtual QString identifier(void) const
dtkAbstractProcess * createaxlLineCreator(void)
virtual QString description(void) const
virtual dtkAbstractData * output(void)
virtual void setInput(dtkAbstractData *newData, int channel)
virtual int update(void)
axlLineCreator(QObject *parent=0)
virtual axlAbstractData * getInput(int channel) const
bool hasParameters(void)
Class axlAbstractData defines an API for all type of axel data.
virtual ~axlLineCreator(void)