2
// C++ Interface: BluePrint
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2005
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
23
#ifndef CARPENTERBLUEPRINT_H
24
#define CARPENTERBLUEPRINT_H
25
// ------------------------------
26
// Include WFmath header files
27
// ------------------------------
28
#include <wfmath/point.h>
29
#include <wfmath/vector.h>
30
#include <wfmath/axisbox.h>
31
#include <wfmath/quaternion.h>
33
#include "Carpenter.h"
41
class BuildingBlockSpec;
42
class BuildingBlockSpecDefinition;
43
class BuildingBlockBinding;
44
class BuildingBlockBindingDefinition;
45
class BuildingBlockDefinition;
50
@author Erik Hjortsberg
55
class BuildingBlockBindingDefinition
58
BuildingBlockBindingDefinition() {}
59
std::string mBlock1Name;
60
std::string mBlock2Name;
61
std::string mPair1Name;
62
std::string mPair2Name;
63
std::string mPoint1Name;
64
std::string mPoint2Name;
67
class BuildingBlockBinding
69
friend class BluePrint;
71
BuildingBlockBinding(const BuildingBlock* block1, const AttachPoint* point1, const BuildingBlock* block2, const AttachPoint* point2);
72
const std::string& getType() const;
73
const BuildingBlock* getBlock1() const { return mBlock1; }
74
const BuildingBlock* getBlock2() const { return mBlock2; }
75
const AttachPoint* getAttachPoint1() const { return mPoint1; }
76
const AttachPoint* getAttachPoint2() const { return mPoint2; }
80
const BuildingBlock* mBlock1;
81
const AttachPoint* mPoint1;
82
const BuildingBlock* mBlock2;
83
const AttachPoint* mPoint2;
94
class BuildingBlockDefinition
97
BuildingBlockDefinition() {}
99
std::string mBuildingBlockSpec;
104
friend class BluePrint;
107
const std::vector<BuildingBlockBinding*> getBindingsForBlock() const;
108
const AttachPair* getAttachPair(const std::string& name);
109
const std::string& getName() const { return mBlockDefinition.mName; }
112
WFMath::Point<3> getWorldPositionForPoint(const AttachPoint* point);
113
bool isAttached() const;
117
void setPosition(WFMath::Point<3> position);
118
void setOrientation(WFMath::Quaternion orientation);
119
const WFMath::Point<3>& getPosition() const;
120
const WFMath::Quaternion& getOrientation() const;
122
const BuildingBlockSpec* getBuildingBlockSpec() const;
124
const BlockSpec* getBlockSpec() const;
126
const std::vector<const AttachPoint*> getAllPoints() const;
129
* the number of bindings that are dependant on this block
130
as long as it's more than zero, the block cannot be deleted
133
int getNumberOfChildBindings() const;
136
//ModelBlock mModelBlock;
137
BuildingBlockSpec* mBuildingBlockSpec;
138
BuildingBlockDefinition mBlockDefinition;
139
WFMath::Point<3> mPosition;
140
WFMath::Quaternion mOrientation;
143
A vector of all points that are already bound
145
std::vector<const AttachPoint*> mBoundPoints;
148
* removes a point from the list of bound points
151
void removeBoundPoint(const AttachPoint* point);
154
the number of bindings that are dependant on this block
155
as long as it's more than zero, the block cannot be deleted
162
inline bool BuildingBlock::isAttached() const { return mAttached; }
163
inline void BuildingBlock::setPosition(WFMath::Point<3> position) { mPosition = position;}
164
inline void BuildingBlock::setOrientation(WFMath::Quaternion orientation) { mOrientation = orientation;}
165
inline const WFMath::Point<3>& BuildingBlock::getPosition() const { return mPosition;}
166
inline const WFMath::Quaternion& BuildingBlock::getOrientation() const { return mOrientation;}
167
inline const BuildingBlockSpec* BuildingBlock::getBuildingBlockSpec() const { return mBuildingBlockSpec; }
168
inline const BlockSpec* BuildingBlock::getBlockSpec() const { return mBuildingBlockSpec->getBlockSpec(); }
169
inline int BuildingBlock::getNumberOfChildBindings() const { return mChildBindings; }
178
BluePrint(const std::string & name, Carpenter* carpenter);
180
const std::string& getName() const;
183
* compiles the blueprint into a structure
187
BuildingBlock* createBuildingBlock(BuildingBlockDefinition);
190
* deletes a building block from the blueprint
193
// void deleteBuildingBlock(const std::string & name);
195
BuildingBlockBinding* addBinding(BuildingBlockBindingDefinition definition);
196
BuildingBlockBinding* addBinding(const BuildingBlock* block1, const AttachPoint* point1, const BuildingBlock* block2, const AttachPoint* point2);
197
const std::vector< BuildingBlock*> getAttachedBlocks() const;
198
const std::list< BuildingBlockBinding>* getBindings() const;
201
* accessor for the name of the starting block
204
void setStartingBlock(const std::string& name);
205
const BuildingBlock* getStartingBlock() const;
208
* Places the unbound block in the supplied bindings correctly
211
void placeBindings(BuildingBlock* unboundBlock, std::vector<BuildingBlockBinding*> bindings);
213
Carpenter* const getCarpenter();
217
* true if the building block can be removed from the blueprint
221
bool isRemovable(const BuildingBlock* bblock) const;
224
* removes the building block from the blueprint, if it can be removed
228
bool remove(const BuildingBlock* bblock);
230
typedef std::map<const std::string, BuildingBlock> BuildingBlockStore;
232
BuildingBlockStore mBuildingBlocks;
233
std::list< BuildingBlockBinding> mBindings;
235
std::vector< BuildingBlock*> mAttachedBlocks;
236
BuildingBlock* mStartingBlock;
239
Carpenter* mCarpenter;
242
void doBindingsForBlock(BuildingBlock *block);
246
inline Carpenter* const BluePrint::getCarpenter() { return mCarpenter;}
247
inline const std::string& BluePrint::getName() const {return mName;}
248
inline const BuildingBlock* BluePrint::getStartingBlock() const {return mStartingBlock;}