102be5353SAxel Dörfler/*
202be5353SAxel DörflerOpen Tracker License
302be5353SAxel Dörfler
402be5353SAxel DörflerTerms and Conditions
502be5353SAxel Dörfler
602be5353SAxel DörflerCopyright (c) 1991-2000, Be Incorporated. All rights reserved.
702be5353SAxel Dörfler
802be5353SAxel DörflerPermission is hereby granted, free of charge, to any person obtaining a copy of
902be5353SAxel Dörflerthis software and associated documentation files (the "Software"), to deal in
1002be5353SAxel Dörflerthe Software without restriction, including without limitation the rights to
1102be5353SAxel Dörfleruse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
1202be5353SAxel Dörflerof the Software, and to permit persons to whom the Software is furnished to do
1302be5353SAxel Dörflerso, subject to the following conditions:
1402be5353SAxel Dörfler
1502be5353SAxel DörflerThe above copyright notice and this permission notice applies to all licensees
1602be5353SAxel Dörflerand shall be included in all copies or substantial portions of the Software.
1702be5353SAxel Dörfler
1802be5353SAxel DörflerTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1902be5353SAxel DörflerIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
2002be5353SAxel DörflerFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2102be5353SAxel DörflerBE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
2202be5353SAxel DörflerAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
2302be5353SAxel DörflerWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2402be5353SAxel Dörfler
2502be5353SAxel DörflerExcept as contained in this notice, the name of Be Incorporated shall not be
2602be5353SAxel Dörflerused in advertising or otherwise to promote the sale, use or other dealings in
2702be5353SAxel Dörflerthis Software without prior written authorization from Be Incorporated.
2802be5353SAxel Dörfler
2902be5353SAxel DörflerTracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
3002be5353SAxel Dörflerof Be Incorporated in the United States and other countries. Other brand product
3102be5353SAxel Dörflernames are registered trademarks or trademarks of their respective holders.
3202be5353SAxel DörflerAll rights reserved.
3302be5353SAxel Dörfler*/
3402be5353SAxel Dörfler
3502be5353SAxel Dörfler//	Icon cache is used for drawing node icons; it caches icons
3602be5353SAxel Dörfler//	and reuses them for successive draws
3702be5353SAxel Dörfler
3802be5353SAxel Dörfler#include <Debug.h>
3902be5353SAxel Dörfler
4002be5353SAxel Dörfler#include "PoseList.h"
4102be5353SAxel Dörfler
4202be5353SAxel Dörfler
43b05aa8b5SJohn ScipioneBPose*
44b05aa8b5SJohn ScipionePoseList::FindPose(const node_ref* node, int32* resultingIndex) const
4502be5353SAxel Dörfler{
4602be5353SAxel Dörfler	int32 count = CountItems();
4702be5353SAxel Dörfler	for (int32 index = 0; index < count; index++) {
48b05aa8b5SJohn Scipione		BPose* pose = ItemAt(index);
4902be5353SAxel Dörfler		ASSERT(pose->TargetModel());
5002be5353SAxel Dörfler		if (*pose->TargetModel()->NodeRef() == *node) {
51fdb62486SJohn Scipione			if (resultingIndex != NULL)
5202be5353SAxel Dörfler				*resultingIndex = index;
53b05aa8b5SJohn Scipione
5402be5353SAxel Dörfler			return pose;
5502be5353SAxel Dörfler		}
5602be5353SAxel Dörfler	}
57fdb62486SJohn Scipione
5802be5353SAxel Dörfler	return NULL;
5902be5353SAxel Dörfler}
6002be5353SAxel Dörfler
61b05aa8b5SJohn Scipione
62b05aa8b5SJohn ScipioneBPose*
63b05aa8b5SJohn ScipionePoseList::FindPose(const entry_ref* entry, int32* resultingIndex) const
6402be5353SAxel Dörfler{
6502be5353SAxel Dörfler	int32 count = CountItems();
6602be5353SAxel Dörfler	for (int32 index = 0; index < count; index++) {
67b05aa8b5SJohn Scipione		BPose* pose = ItemAt(index);
6802be5353SAxel Dörfler		ASSERT(pose->TargetModel());
6902be5353SAxel Dörfler		if (*pose->TargetModel()->EntryRef() == *entry) {
70fdb62486SJohn Scipione			if (resultingIndex != NULL)
7102be5353SAxel Dörfler				*resultingIndex = index;
72b05aa8b5SJohn Scipione
7302be5353SAxel Dörfler			return pose;
7402be5353SAxel Dörfler		}
7502be5353SAxel Dörfler	}
7602be5353SAxel Dörfler	return NULL;
7702be5353SAxel Dörfler}
7802be5353SAxel Dörfler
79b05aa8b5SJohn Scipione
80b05aa8b5SJohn ScipioneBPose*
81b05aa8b5SJohn ScipionePoseList::FindPose(const Model* model, int32* resultingIndex) const
8202be5353SAxel Dörfler{
8302be5353SAxel Dörfler	return FindPose(model->NodeRef(), resultingIndex);
8402be5353SAxel Dörfler}
8502be5353SAxel Dörfler
86b05aa8b5SJohn Scipione
87b05aa8b5SJohn ScipioneBPose*
88b05aa8b5SJohn ScipionePoseList::DeepFindPose(const node_ref* node, int32* resultingIndex) const
8902be5353SAxel Dörfler{
9002be5353SAxel Dörfler	int32 count = CountItems();
9102be5353SAxel Dörfler	for (int32 index = 0; index < count; index++) {
92b05aa8b5SJohn Scipione		BPose* pose = ItemAt(index);
93b05aa8b5SJohn Scipione		Model* model = pose->TargetModel();
9402be5353SAxel Dörfler		if (*model->NodeRef() == *node) {
95fdb62486SJohn Scipione			if (resultingIndex != NULL)
9602be5353SAxel Dörfler				*resultingIndex = index;
97b05aa8b5SJohn Scipione
9802be5353SAxel Dörfler			return pose;
9902be5353SAxel Dörfler		}
10002be5353SAxel Dörfler		// if model is a symlink, try matching node with the target
10102be5353SAxel Dörfler		// of the link
10202be5353SAxel Dörfler		if (model->IsSymLink()) {
10302be5353SAxel Dörfler			model = model->LinkTo();
104fdb62486SJohn Scipione			if (model != NULL && *model->NodeRef() == *node) {
105fdb62486SJohn Scipione				if (resultingIndex != NULL)
10602be5353SAxel Dörfler					*resultingIndex = index;
107b05aa8b5SJohn Scipione
10802be5353SAxel Dörfler				return pose;
10902be5353SAxel Dörfler			}
11002be5353SAxel Dörfler		}
11102be5353SAxel Dörfler	}
11202be5353SAxel Dörfler
11302be5353SAxel Dörfler	return NULL;
11402be5353SAxel Dörfler}
115c2535dc4SPhilippe Saint-Pierre
116c2535dc4SPhilippe Saint-Pierre
117e0e641c0SPhilippe Saint-PierrePoseList*
118e0e641c0SPhilippe Saint-PierrePoseList::FindAllPoses(const node_ref* node) const
119c2535dc4SPhilippe Saint-Pierre{
120c2535dc4SPhilippe Saint-Pierre	int32 count = CountItems();
121c2535dc4SPhilippe Saint-Pierre	PoseList *result = new PoseList(5, false);
122c2535dc4SPhilippe Saint-Pierre	for (int32 index = 0; index < count; index++) {
123c2535dc4SPhilippe Saint-Pierre		BPose *pose = ItemAt(index);
124c2535dc4SPhilippe Saint-Pierre		Model *model = pose->TargetModel();
125c2535dc4SPhilippe Saint-Pierre		if (*model->NodeRef() == *node) {
126c2535dc4SPhilippe Saint-Pierre			result->AddItem(pose, 0);
127c2535dc4SPhilippe Saint-Pierre			continue;
128c2535dc4SPhilippe Saint-Pierre		}
129db416834SMatt Madia
1307d460e3bSPhilippe Saint-Pierre		if (!model->IsSymLink())
1317d460e3bSPhilippe Saint-Pierre			continue;
1327d460e3bSPhilippe Saint-Pierre
133c2535dc4SPhilippe Saint-Pierre		model = model->LinkTo();
134e0e641c0SPhilippe Saint-Pierre		if (model != NULL && *model->NodeRef() == *node) {
135c2535dc4SPhilippe Saint-Pierre			result->AddItem(pose);
136c2535dc4SPhilippe Saint-Pierre			continue;
137c2535dc4SPhilippe Saint-Pierre		}
138db416834SMatt Madia
139e0e641c0SPhilippe Saint-Pierre		if (model == NULL) {
140e0e641c0SPhilippe Saint-Pierre			Model model(pose->TargetModel()->EntryRef(), true);
141e0e641c0SPhilippe Saint-Pierre			if (*model.NodeRef() == *node)
142c2535dc4SPhilippe Saint-Pierre				result->AddItem(pose);
143c2535dc4SPhilippe Saint-Pierre		}
144c2535dc4SPhilippe Saint-Pierre	}
145fdb62486SJohn Scipione
146c2535dc4SPhilippe Saint-Pierre	return result;
147c2535dc4SPhilippe Saint-Pierre}
1481c29b26eSIngo Weinhold
1491c29b26eSIngo Weinhold
1501c29b26eSIngo WeinholdBPose*
1511c29b26eSIngo WeinholdPoseList::FindPoseByFileName(const char* name, int32* _index) const
1521c29b26eSIngo Weinhold{
1531c29b26eSIngo Weinhold	int32 count = CountItems();
1541c29b26eSIngo Weinhold	for (int32 index = 0; index < count; index++) {
1551c29b26eSIngo Weinhold		BPose* pose = ItemAt(index);
1561c29b26eSIngo Weinhold		ASSERT(pose->TargetModel());
1571c29b26eSIngo Weinhold		if (strcmp(pose->TargetModel()->EntryRef()->name, name) == 0) {
158fdb62486SJohn Scipione			if (_index != NULL)
1591c29b26eSIngo Weinhold				*_index = index;
1601c29b26eSIngo Weinhold
1611c29b26eSIngo Weinhold			return pose;
1621c29b26eSIngo Weinhold		}
1631c29b26eSIngo Weinhold	}
164fdb62486SJohn Scipione
1651c29b26eSIngo Weinhold	return NULL;
1661c29b26eSIngo Weinhold}
167