| 1 | // | 
|---|
| 2 | // object.cc | 
|---|
| 3 | // | 
|---|
| 4 | // Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
| 5 | // | 
|---|
| 6 | // Author: Curtis Janssen <cljanss@limitpt.com> | 
|---|
| 7 | // Maintainer: LPS | 
|---|
| 8 | // | 
|---|
| 9 | // This file is part of the SC Toolkit. | 
|---|
| 10 | // | 
|---|
| 11 | // The SC Toolkit is free software; you can redistribute it and/or modify | 
|---|
| 12 | // it under the terms of the GNU Library General Public License as published by | 
|---|
| 13 | // the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 14 | // any later version. | 
|---|
| 15 | // | 
|---|
| 16 | // The SC Toolkit is distributed in the hope that it will be useful, | 
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 19 | // GNU Library General Public License for more details. | 
|---|
| 20 | // | 
|---|
| 21 | // You should have received a copy of the GNU Library General Public License | 
|---|
| 22 | // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to | 
|---|
| 23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 24 | // | 
|---|
| 25 | // The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
| 26 | // | 
|---|
| 27 |  | 
|---|
| 28 | #ifdef __GNUC__ | 
|---|
| 29 | #pragma implementation | 
|---|
| 30 | #endif | 
|---|
| 31 |  | 
|---|
| 32 | #include <stdlib.h> | 
|---|
| 33 | #include <util/misc/formio.h> | 
|---|
| 34 | #include <util/render/render.h> | 
|---|
| 35 | #include <util/render/object.h> | 
|---|
| 36 |  | 
|---|
| 37 | using namespace std; | 
|---|
| 38 | using namespace sc; | 
|---|
| 39 |  | 
|---|
| 40 | static ClassDesc RenderedObject_cd( | 
|---|
| 41 | typeid(RenderedObject),"RenderedObject",1,"public DescribedClass", | 
|---|
| 42 | 0, 0, 0); | 
|---|
| 43 |  | 
|---|
| 44 | RenderedObject::RenderedObject(const Ref<Material>& material): | 
|---|
| 45 | name_(0), | 
|---|
| 46 | material_(material) | 
|---|
| 47 | { | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | RenderedObject::RenderedObject(const Ref<KeyVal>& keyval) | 
|---|
| 51 | { | 
|---|
| 52 | name_ = keyval->pcharvalue("name"); | 
|---|
| 53 | material_ << keyval->describedclassvalue("material"); | 
|---|
| 54 | appearance_ << keyval->describedclassvalue("appearance"); | 
|---|
| 55 | transform_ << keyval->describedclassvalue("transform"); | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 | RenderedObject::~RenderedObject() | 
|---|
| 59 | { | 
|---|
| 60 |  | 
|---|
| 61 | if (name_) delete[] name_; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | void | 
|---|
| 65 | RenderedObject::set_name(const char *name) | 
|---|
| 66 | { | 
|---|
| 67 | delete[] name_; | 
|---|
| 68 | if (name) name_ = strcpy(new char[strlen(name)+1],name); | 
|---|
| 69 | else name_ = 0; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | void | 
|---|
| 73 | RenderedObject::print(ostream& os) const | 
|---|
| 74 | { | 
|---|
| 75 | os << "RenderedObject:" << endl; | 
|---|
| 76 | if (material_.nonnull()) { | 
|---|
| 77 | os << scprintf("  material = 0x%x\n", material_.pointer()); | 
|---|
| 78 | } | 
|---|
| 79 | if (appearance_.nonnull()) { | 
|---|
| 80 | os << scprintf("  appearance = 0x%x\n", appearance_.pointer()); | 
|---|
| 81 | } | 
|---|
| 82 | if (transform_.nonnull()) { | 
|---|
| 83 | os << scprintf("  transform = 0x%x\n", transform_.pointer()); | 
|---|
| 84 | } | 
|---|
| 85 | os.flush(); | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 |  | 
|---|
| 89 | static ClassDesc RenderedObjectSet_cd( | 
|---|
| 90 | typeid(RenderedObjectSet),"RenderedObjectSet",1,"public RenderedObject", | 
|---|
| 91 | 0, create<RenderedObjectSet>, 0); | 
|---|
| 92 |  | 
|---|
| 93 | RenderedObjectSet::RenderedObjectSet(int capacity) | 
|---|
| 94 | { | 
|---|
| 95 | capacity_ = capacity; | 
|---|
| 96 | n_ = 0; | 
|---|
| 97 | array_ = new Ref<RenderedObject>[capacity_]; | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | RenderedObjectSet::RenderedObjectSet(const Ref<KeyVal>& keyval): | 
|---|
| 101 | RenderedObject(keyval) | 
|---|
| 102 | { | 
|---|
| 103 | capacity_ = keyval->count("objects"); | 
|---|
| 104 | if (keyval->error() != KeyVal::OK) { | 
|---|
| 105 | ExEnv::errn() << "RenderedObjectSet: error counting objects" << endl; | 
|---|
| 106 | abort(); | 
|---|
| 107 | } | 
|---|
| 108 | n_ = capacity_; | 
|---|
| 109 | array_ = new Ref<RenderedObject>[capacity_]; | 
|---|
| 110 | for (int i=0; i<n_; i++) { | 
|---|
| 111 | array_[i] << keyval->describedclassvalue("objects",i); | 
|---|
| 112 | if (keyval->error() != KeyVal::OK) { | 
|---|
| 113 | ExEnv::errn() << "RenderedObjectSet: error reading objects" << endl; | 
|---|
| 114 | abort(); | 
|---|
| 115 | } | 
|---|
| 116 | } | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | RenderedObjectSet::~RenderedObjectSet() | 
|---|
| 120 | { | 
|---|
| 121 | delete[] array_; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | void | 
|---|
| 125 | RenderedObjectSet::add(const Ref<RenderedObject>& object) | 
|---|
| 126 | { | 
|---|
| 127 | if (capacity_ == n_) { | 
|---|
| 128 | capacity_ += 10; | 
|---|
| 129 | Ref<RenderedObject> *tmp = new Ref<RenderedObject>[capacity_]; | 
|---|
| 130 | for (int i=0; i<n_; i++) { | 
|---|
| 131 | tmp[i] = array_[i]; | 
|---|
| 132 | } | 
|---|
| 133 | delete[] array_; | 
|---|
| 134 | array_ = tmp; | 
|---|
| 135 | } | 
|---|
| 136 | array_[n_] = object; | 
|---|
| 137 | n_++; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | void | 
|---|
| 141 | RenderedObjectSet::render(const Ref<Render>& render) | 
|---|
| 142 | { | 
|---|
| 143 | render->set(this); | 
|---|
| 144 | } | 
|---|
| 145 |  | 
|---|
| 146 | ///////////////////////////////////////////////////////////////////////////// | 
|---|
| 147 |  | 
|---|
| 148 | // Local Variables: | 
|---|
| 149 | // mode: c++ | 
|---|
| 150 | // c-file-style: "CLJ" | 
|---|
| 151 | // End: | 
|---|