1 | //
|
---|
2 | // File: MPQC_Chemistry_MoleculeViewer_Impl.cc
|
---|
3 | // Symbol: MPQC.Chemistry_MoleculeViewer-v0.2
|
---|
4 | // Symbol Type: class
|
---|
5 | // Babel Version: 0.10.2
|
---|
6 | // Description: Server-side implementation for MPQC.Chemistry_MoleculeViewer
|
---|
7 | //
|
---|
8 | // WARNING: Automatically generated; only changes within splicers preserved
|
---|
9 | //
|
---|
10 | // babel-version = 0.10.2
|
---|
11 | //
|
---|
12 | #include "MPQC_Chemistry_MoleculeViewer_Impl.hh"
|
---|
13 |
|
---|
14 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer._includes)
|
---|
15 | #include <sstream>
|
---|
16 | #include <iostream>
|
---|
17 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer._includes)
|
---|
18 |
|
---|
19 | // user-defined constructor.
|
---|
20 | void MPQC::Chemistry_MoleculeViewer_impl::_ctor() {
|
---|
21 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer._ctor)
|
---|
22 | is_updated=0;
|
---|
23 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer._ctor)
|
---|
24 | }
|
---|
25 |
|
---|
26 | // user-defined destructor.
|
---|
27 | void MPQC::Chemistry_MoleculeViewer_impl::_dtor() {
|
---|
28 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer._dtor)
|
---|
29 |
|
---|
30 | #if USE_SOCKET
|
---|
31 | try {
|
---|
32 | socket_.close();
|
---|
33 | }
|
---|
34 | catch (std::exception &e) {
|
---|
35 | std::cout << "NOTE: could not close viewer connection: "
|
---|
36 | << e.what()
|
---|
37 | << std::endl;
|
---|
38 | }
|
---|
39 | #endif // USE_SOCKET
|
---|
40 |
|
---|
41 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer._dtor)
|
---|
42 | }
|
---|
43 |
|
---|
44 | // static class initializer.
|
---|
45 | void MPQC::Chemistry_MoleculeViewer_impl::_load() {
|
---|
46 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer._load)
|
---|
47 | // guaranteed to be called at most once before any other method in this class
|
---|
48 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer._load)
|
---|
49 | }
|
---|
50 |
|
---|
51 | // user-defined static methods: (none)
|
---|
52 |
|
---|
53 | // user-defined non-static methods:
|
---|
54 | /**
|
---|
55 | * Method: set_molecule[]
|
---|
56 | */
|
---|
57 | void
|
---|
58 | MPQC::Chemistry_MoleculeViewer_impl::set_molecule (
|
---|
59 | /* in */ ::Chemistry::Molecule molecule )
|
---|
60 | throw ()
|
---|
61 | {
|
---|
62 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer.set_molecule)
|
---|
63 | molecule_ = molecule;
|
---|
64 | is_updated=1;
|
---|
65 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer.set_molecule)
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Method: set_coor[]
|
---|
70 | */
|
---|
71 | void
|
---|
72 | MPQC::Chemistry_MoleculeViewer_impl::set_coor (
|
---|
73 | /* in */ const ::std::string& coords )
|
---|
74 | throw ()
|
---|
75 | {
|
---|
76 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer.set_coor)
|
---|
77 | // insert implementation here
|
---|
78 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer.set_coor)
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Method: run_gui[]
|
---|
83 | */
|
---|
84 | void
|
---|
85 | MPQC::Chemistry_MoleculeViewer_impl::run_gui ()
|
---|
86 | throw ()
|
---|
87 |
|
---|
88 | {
|
---|
89 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer.run_gui)
|
---|
90 | // insert implementation here
|
---|
91 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer.run_gui)
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Method: draw[]
|
---|
96 | */
|
---|
97 | void
|
---|
98 | MPQC::Chemistry_MoleculeViewer_impl::draw ()
|
---|
99 | throw ()
|
---|
100 |
|
---|
101 | {
|
---|
102 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer.draw)
|
---|
103 | if (molecule_._is_nil()) {
|
---|
104 | return;
|
---|
105 | }
|
---|
106 |
|
---|
107 | std::cout << "drawing" << std::endl;
|
---|
108 |
|
---|
109 | for (int i=0; i<molecule_.get_n_atom(); i++) {
|
---|
110 | std::cout << "====="
|
---|
111 | << " " << molecule_.get_cart_coor(i,0)
|
---|
112 | << " " << molecule_.get_cart_coor(i,1)
|
---|
113 | << " " << molecule_.get_cart_coor(i,2)
|
---|
114 | << std::endl;
|
---|
115 | }
|
---|
116 |
|
---|
117 | #if USE_SOCKET
|
---|
118 | try {
|
---|
119 |
|
---|
120 | if (!socket_.initialized()) socket_.create();
|
---|
121 | if (!socket_.bound()) socket_.bind(10002,12000);
|
---|
122 | if (!socket_.connected()) socket_.connect("localhost", 10001);
|
---|
123 |
|
---|
124 | std::ostringstream str;
|
---|
125 | const double f = 1.0/(1.0e-10/5.29177249e-11); // m
|
---|
126 | for (int i=0; i<molecule_.get_n_atom(); i++) {
|
---|
127 | str << " " << f*molecule_.get_cart_coor(i,0)
|
---|
128 | << " " << f*molecule_.get_cart_coor(i,1)
|
---|
129 | << " " << f*molecule_.get_cart_coor(i,2);
|
---|
130 | }
|
---|
131 | str << " ";
|
---|
132 | socket_.write(str.str().c_str(), str.str().size());
|
---|
133 | std::cout << "sent to socket: " << str.str() << std::endl;
|
---|
134 | }
|
---|
135 | catch (std::exception &e) {
|
---|
136 | std::cout << "NOTE: Could not draw to viewer: "
|
---|
137 | << e.what()
|
---|
138 | << std::endl;
|
---|
139 | }
|
---|
140 | #endif // USE_SOCKET
|
---|
141 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer.draw)
|
---|
142 | }
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Starts up a component presence in the calling framework.
|
---|
146 | * @param Svc the component instance's handle on the framework world.
|
---|
147 | * Contracts concerning Svc and setServices:
|
---|
148 | *
|
---|
149 | * The component interaction with the CCA framework
|
---|
150 | * and Ports begins on the call to setServices by the framework.
|
---|
151 | *
|
---|
152 | * This function is called exactly once for each instance created
|
---|
153 | * by the framework.
|
---|
154 | *
|
---|
155 | * The argument Svc will never be nil/null.
|
---|
156 | *
|
---|
157 | * Those uses ports which are automatically connected by the framework
|
---|
158 | * (so-called service-ports) may be obtained via getPort during
|
---|
159 | * setServices.
|
---|
160 | */
|
---|
161 | void
|
---|
162 | MPQC::Chemistry_MoleculeViewer_impl::setServices (
|
---|
163 | /* in */ ::gov::cca::Services services )
|
---|
164 | throw (
|
---|
165 | ::gov::cca::CCAException
|
---|
166 | ){
|
---|
167 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer.setServices)
|
---|
168 | services.addProvidesPort(self,"MoleculeViewer","Chemistry.MoleculeViewer",
|
---|
169 | services.createTypeMap());
|
---|
170 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer.setServices)
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | // DO-NOT-DELETE splicer.begin(MPQC.Chemistry_MoleculeViewer._misc)
|
---|
175 | // Put miscellaneous code here
|
---|
176 | // DO-NOT-DELETE splicer.end(MPQC.Chemistry_MoleculeViewer._misc)
|
---|
177 |
|
---|