From 6589c8c31fd27bf05df37d54e883ad24a146273a Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 6 Feb 2001 22:44:54 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/graph/nodeRelation.I | 17 +++++++++++++++- panda/src/graph/nodeRelation.h | 3 ++- panda/src/parametrics/nurbsCurve.cxx | 13 ++++++++---- panda/src/parametrics/nurbsCurve.h | 2 +- panda/src/putil/modifierButtons.I | 11 ++++++++++ panda/src/putil/modifierButtons.h | 1 + panda/src/sgmanip/nodePath.I | 4 ++-- panda/src/sgmanip/nodePath.cxx | 21 +++++++++---------- panda/src/sgmanip/nodePath.h | 19 ++++++++++-------- panda/src/tform/dataValve.cxx | 30 +++++++++++++++++++++++----- panda/src/tform/dataValve.h | 7 +++++++ 11 files changed, 96 insertions(+), 32 deletions(-) diff --git a/panda/src/graph/nodeRelation.I b/panda/src/graph/nodeRelation.I index 839f78cdf3..1285edb48d 100644 --- a/panda/src/graph/nodeRelation.I +++ b/panda/src/graph/nodeRelation.I @@ -136,6 +136,20 @@ change_parent(Node *parent) { attach(); } +//////////////////////////////////////////////////////////////////// +// Function: NodeRelation::change_parent +// Access: Public +// Description: Changes the parent of the arc to a different node, +// simultaneously changing the sort index. +//////////////////////////////////////////////////////////////////// +INLINE void NodeRelation:: +change_parent(Node *parent, int sort) { + PT(NodeRelation) hold_arc = detach(); + _parent = parent; + _sort = sort; + attach(); +} + //////////////////////////////////////////////////////////////////// // Function: NodeRelation::change_child // Access: Public @@ -337,11 +351,12 @@ get_last_update() const { // the type is unknown. //////////////////////////////////////////////////////////////////// INLINE NodeRelation *NodeRelation:: -create_typed_arc(TypeHandle type, Node *parent, Node *child) { +create_typed_arc(TypeHandle type, Node *parent, Node *child, int sort) { NodeRelation *arc = get_factory().make_instance(type); if (arc != (NodeRelation *)NULL) { arc->_parent = parent; arc->_child = child; + arc->_sort = sort; arc->attach(); } return arc; diff --git a/panda/src/graph/nodeRelation.h b/panda/src/graph/nodeRelation.h index 05909399d2..6130504310 100644 --- a/panda/src/graph/nodeRelation.h +++ b/panda/src/graph/nodeRelation.h @@ -82,6 +82,7 @@ PUBLISHED: INLINE int get_sort() const; INLINE void change_parent(Node *parent); + INLINE void change_parent(Node *parent, int sort); INLINE void change_child(Node *child); INLINE void change_parent_and_child(Node *parent, Node *child); INLINE void set_sort(int sort); @@ -115,7 +116,7 @@ public: // Factory stuff: to create a new NodeRelation based on its // TypeHandle. INLINE static NodeRelation * - create_typed_arc(TypeHandle type, Node *parent, Node *child); + create_typed_arc(TypeHandle type, Node *parent, Node *child, int sort = 0); // This is just to be called at initialization time; don't try to // call this directly. diff --git a/panda/src/parametrics/nurbsCurve.cxx b/panda/src/parametrics/nurbsCurve.cxx index d01988429c..8e158b6f06 100644 --- a/panda/src/parametrics/nurbsCurve.cxx +++ b/panda/src/parametrics/nurbsCurve.cxx @@ -348,7 +348,9 @@ get_knot(int n) const { // Description: //////////////////////////////////////////////////////////////////// void NurbsCurve:: -write(ostream &out) const { +write(ostream &out, int indent_level) const { + indent(out, indent_level); + switch (get_curve_type()) { case PCT_T: out << "Time-warping "; @@ -369,14 +371,17 @@ write(ostream &out) const { out << "NurbsCurve, order " << _order << ", " << get_num_cvs() << " CV's. t ranges from 0 to " << get_max_t() << ".\n"; - out << "CV's:\n"; + indent(out, indent_level) + << "CV's:\n"; int i; for (i = 0; i < (int)_cvs.size(); i++) { LVecBase3f p = (const LVecBase3f &)_cvs[i]._p / _cvs[i]._p[3]; - out << i << ") " << p << ", weight " << _cvs[i]._p[3] << "\n"; + indent(out, indent_level) + << i << ") " << p << ", weight " << _cvs[i]._p[3] << "\n"; } - out << "Knots: "; + indent(out, indent_level) + << "Knots: "; for (i = 0; i < (int)_cvs.size()+_order; i++) { out << " " << GetKnot(i); } diff --git a/panda/src/parametrics/nurbsCurve.h b/panda/src/parametrics/nurbsCurve.h index 626c0895b7..a0a101ea22 100644 --- a/panda/src/parametrics/nurbsCurve.h +++ b/panda/src/parametrics/nurbsCurve.h @@ -87,7 +87,7 @@ PUBLISHED: bool set_knot(int n, double t); double get_knot(int n) const; - void write(ostream &out) const; + virtual void write(ostream &out, int indent_level = 0) const; void write_cv(ostream &out, int n) const; bool recompute(); diff --git a/panda/src/putil/modifierButtons.I b/panda/src/putil/modifierButtons.I index 52cabe9e64..4c8a6ee2d0 100644 --- a/panda/src/putil/modifierButtons.I +++ b/panda/src/putil/modifierButtons.I @@ -90,6 +90,17 @@ add_event(const ButtonEvent &event) { } } +//////////////////////////////////////////////////////////////////// +// Function: ModifierButtons::all_buttons_up +// Access: Public +// Description: Marks all monitored buttons as being in the "up" +// state. +//////////////////////////////////////////////////////////////////// +INLINE void ModifierButtons:: +all_buttons_up() { + _state = 0; +} + //////////////////////////////////////////////////////////////////// // Function: ModifierButtons::is_down // Access: Public diff --git a/panda/src/putil/modifierButtons.h b/panda/src/putil/modifierButtons.h index 9133c22089..718311fa1a 100644 --- a/panda/src/putil/modifierButtons.h +++ b/panda/src/putil/modifierButtons.h @@ -39,6 +39,7 @@ PUBLISHED: bool button_down(ButtonHandle button); bool button_up(ButtonHandle button); INLINE bool add_event(const ButtonEvent &event); + INLINE void all_buttons_up(); bool is_down(ButtonHandle button) const; INLINE bool is_down(int index) const; diff --git a/panda/src/sgmanip/nodePath.I b/panda/src/sgmanip/nodePath.I index 7575ee388a..cf9b4b95f3 100644 --- a/panda/src/sgmanip/nodePath.I +++ b/panda/src/sgmanip/nodePath.I @@ -430,11 +430,11 @@ find(const string &path) const { // references it. //////////////////////////////////////////////////////////////////// INLINE NodePath NodePath:: -attach_new_node(const string &name) const { +attach_new_node(const string &name, int sort) const { nassertr(verify_connectivity(), NodePath()); nassertr(!is_empty(), NodePath(_graph_type)); - return attach_new_node(new NamedNode(name)); + return attach_new_node(new NamedNode(name), sort); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/sgmanip/nodePath.cxx b/panda/src/sgmanip/nodePath.cxx index 7d49de955e..2c216de8e4 100644 --- a/panda/src/sgmanip/nodePath.cxx +++ b/panda/src/sgmanip/nodePath.cxx @@ -697,7 +697,7 @@ repair_connectivity(const NodePath &top) { // the new path to the node. //////////////////////////////////////////////////////////////////// void NodePath:: -reparent_to(const NodePath &other) { +reparent_to(const NodePath &other, int sort) { nassertv(other.verify_connectivity()); nassertv(has_arcs()); nassertv(_head != (ArcComponent *)NULL); @@ -705,7 +705,7 @@ reparent_to(const NodePath &other) { NodeRelation *arc = _head->_arc; - arc->change_parent(other.get_bottom_node()); + arc->change_parent(other.get_bottom_node(), sort); // Move our head pointer to the bottom of the new chain. This will // update our own path, as well as all paths that share the same @@ -723,7 +723,7 @@ reparent_to(const NodePath &other) { // different coordinate system. //////////////////////////////////////////////////////////////////// void NodePath:: -wrt_reparent_to(const NodePath &other) { +wrt_reparent_to(const NodePath &other, int sort) { nassertv(other.verify_connectivity()); nassertv(has_arcs()); nassertv(_head != (ArcComponent *)NULL); @@ -732,7 +732,7 @@ wrt_reparent_to(const NodePath &other) { LMatrix4f mat = get_mat(other); set_mat(mat); - reparent_to(other); + reparent_to(other, sort); } //////////////////////////////////////////////////////////////////// @@ -756,14 +756,15 @@ wrt_reparent_to(const NodePath &other) { // node. //////////////////////////////////////////////////////////////////// NodePath NodePath:: -instance_to(const NodePath &other) const { +instance_to(const NodePath &other, int sort) const { nassertr(verify_connectivity(), NodePath()); nassertr(!is_empty(), NodePath()); nassertr(!other.is_empty(), NodePath()); Node *node = get_bottom_node(); NodeRelation *arc = - NodeRelation::create_typed_arc(_graph_type, other.get_bottom_node(), node); + NodeRelation::create_typed_arc(_graph_type, other.get_bottom_node(), + node, sort); nassertr(arc != (NodeRelation *)NULL, NodePath()); nassertr(arc->is_exact_type(_graph_type), NodePath()); @@ -794,7 +795,7 @@ instance_to(const NodePath &other) const { // NamedNode. //////////////////////////////////////////////////////////////////// NodePath NodePath:: -copy_to(const NodePath &other) const { +copy_to(const NodePath &other, int sort) const { nassertr(verify_connectivity(), NodePath()); nassertr(!is_empty(), NodePath()); nassertr(!other.is_empty(), NodePath()); @@ -805,7 +806,7 @@ copy_to(const NodePath &other) const { NodeRelation *arc = NodeRelation::create_typed_arc(_graph_type, other.get_bottom_node(), - copy_node); + copy_node, sort); nassertr(arc != (NodeRelation *)NULL, NodePath()); nassertr(arc->is_exact_type(_graph_type), NodePath()); @@ -834,13 +835,13 @@ copy_to(const NodePath &other) const { // returned. //////////////////////////////////////////////////////////////////// NodePath NodePath:: -attach_new_node(Node *node) const { +attach_new_node(Node *node, int sort) const { nassertr(verify_connectivity(), NodePath()); nassertr(!is_empty(), NodePath(_graph_type)); nassertr(node != (Node *)NULL, NodePath(_graph_type)); NodePath path(node, _graph_type); - return path.instance_to(*this); + return path.instance_to(*this, sort); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/sgmanip/nodePath.h b/panda/src/sgmanip/nodePath.h index f2a2e50ace..914803c17c 100644 --- a/panda/src/sgmanip/nodePath.h +++ b/panda/src/sgmanip/nodePath.h @@ -176,14 +176,17 @@ PUBLISHED: find_all_matches(const string &path) const; - // Methods that actually move nodes around in the scene graph. - - void reparent_to(const NodePath &other); - void wrt_reparent_to(const NodePath &other); - NodePath instance_to(const NodePath &other) const; - NodePath copy_to(const NodePath &other) const; - NodePath attach_new_node(Node *node) const; - INLINE NodePath attach_new_node(const string &name) const; + // Methods that actually move nodes around in the scene graph. The + // optional "sort" parameter can be used to force a particular + // ordering between sibling nodes, useful when dealing with LOD's + // and similar switch nodes. If the sort value is the same, bnodes + // will be arranged in the order they were added. + void reparent_to(const NodePath &other, int sort = 0); + void wrt_reparent_to(const NodePath &other, int sort = 0); + NodePath instance_to(const NodePath &other, int sort = 0) const; + NodePath copy_to(const NodePath &other, int sort = 0) const; + NodePath attach_new_node(Node *node, int sort = 0) const; + INLINE NodePath attach_new_node(const string &name, int sort = 0) const; void remove_node(); diff --git a/panda/src/tform/dataValve.cxx b/panda/src/tform/dataValve.cxx index 7c92519941..4e2a9df49d 100644 --- a/panda/src/tform/dataValve.cxx +++ b/panda/src/tform/dataValve.cxx @@ -40,6 +40,28 @@ is_on(const DataValve &valve) const { return false; } +//////////////////////////////////////////////////////////////////// +// Function: DataValve::Control::output +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +void DataValve::Control:: +output(ostream &out) const { + switch (_state) { + case S_on: + out << "on"; + break; + + case S_off: + out << "off"; + break; + + case S_buttons: + out << _mods; + break; + } +} + //////////////////////////////////////////////////////////////////// // Function: DataValve::Constructor // Access: Published @@ -214,7 +236,7 @@ void DataValve:: write(ostream &out, int indent_level) const { indent(out, indent_level) << "DataValve " << get_name() << ": (default control is " - << (_default_control->is_on(*this) ? "on" : "off") << ")\n"; + << *_default_control << ")\n"; size_t i; for (i = 0; i < _controls.size(); i++) { @@ -226,7 +248,7 @@ write(ostream &out, int indent_level) const { if (child._control.is_null()) { out << "(default)"; } else { - out << (child._control->is_on(*this) ? "on" : "off"); + out << *child._control; } out << "\n"; @@ -235,9 +257,7 @@ write(ostream &out, int indent_level) const { fci != child._fine_controls.end(); ++fci) { indent(out, indent_level + 4) - << (*fci).first << " " - << ((*fci).second->is_on(*this) ? "on" : "off") - << "\n"; + << (*fci).first << " " << *(*fci).second; } } } diff --git a/panda/src/tform/dataValve.h b/panda/src/tform/dataValve.h index afdd508751..1f22987e6a 100644 --- a/panda/src/tform/dataValve.h +++ b/panda/src/tform/dataValve.h @@ -44,6 +44,8 @@ PUBLISHED: bool is_on(const DataValve &valve) const; + void output(ostream &out) const; + private: enum State { S_on, @@ -119,6 +121,11 @@ private: static TypeHandle _type_handle; }; +INLINE ostream &operator << (ostream &out, const DataValve::Control &control) { + control.output(out); + return out; +} + #include "dataValve.I" #endif