00001 #include "stdafx.h"
00002
00003 #include "BON.h"
00004 #include "BONImpl.h"
00005
00006 #include "ConstraintRep.h"
00007
00008 #include "globals.h"
00009 extern Globals global_vars;
00010
00011
00012 ConstraintRep::ConstraintRep( BON::FCO& ptr)
00013 : Any( ptr),
00014 m_attached( false), m_name(""), m_description(""),
00015 m_defaultParams(""), m_equation(""),
00016 m_priority(0), m_depth(), m_eventMask(0)
00017 {
00018 if (m_ptr)
00019 {
00020 fetch();
00021
00022 m_name = getName();
00023 }
00024 }
00025
00026 void ConstraintRep::attachedTo()
00027 {
00028 m_attached = true;
00029 }
00030
00031 bool ConstraintRep::isAttached() const
00032 {
00033 return m_attached;
00034 }
00035
00036 void ConstraintRep::fetch()
00037 {
00038 std::string desc = m_ptr->getAttribute("ConstraintDescription")->getStringValue();
00039 if(desc.empty()) global_vars.err << MSG_ERROR << "No description found for constraint " << m_ptr << "\n";
00040 m_description = desc;
00041
00042 std::string expr = m_ptr->getAttribute("ConstraintEqn")->getStringValue();
00043 if(expr.empty()) global_vars.err << MSG_ERROR << "No equation found for constraint " << m_ptr << "\n";
00044 m_equation = expr;
00045
00046 std::string priority_str = m_ptr->getAttribute("ConstraintPriority")->getStringValue();
00047 if(sscanf(priority_str.c_str(),"%d",&m_priority) != 1)
00048 m_priority = 2;
00049 m_priority = max(0,min(5,m_priority));
00050
00051 m_depth = m_ptr->getAttribute("Depth")->getStringValue();
00052
00053
00054
00055
00056
00057 m_eventMask = 0;
00058 fetchEventAttribute("CloseEvent",OBJEVENT_CLOSEMODEL);
00059 fetchEventAttribute("NewChildEvent",OBJEVENT_NEWCHILD);
00060 fetchEventAttribute("LostChildEvent",OBJEVENT_LOSTCHILD);
00061 fetchEventAttribute("CreateEvent",OBJEVENT_CREATED);
00062 fetchEventAttribute("DeleteEvent",OBJEVENT_DESTROYED);
00063 fetchEventAttribute("ConnectEvent",OBJEVENT_CONNECTED);
00064 fetchEventAttribute("DisconnectEvent",OBJEVENT_DISCONNECTED);
00065 fetchEventAttribute("ReferenceEvent",OBJEVENT_REFERENCED);
00066 fetchEventAttribute("UnReferenceEvent",OBJEVENT_REFRELEASED);
00067 fetchEventAttribute("AddSetEvent",OBJEVENT_SETINCLUDED);
00068 fetchEventAttribute("RemoveSetEvent",OBJEVENT_SETEXCLUDED);
00069 fetchEventAttribute("ChangeRelationEvent",OBJEVENT_RELATION);
00070 fetchEventAttribute("ChangeAttributeEvent",OBJEVENT_ATTR);
00071 fetchEventAttribute("ChangePropertyEvent",OBJEVENT_PROPERTIES);
00072 fetchEventAttribute("DeriveEvent",OBJEVENT_SUBT_INST);
00073 fetchEventAttribute("MoveEvent",OBJEVENT_PARENT);
00074 }
00075
00076 void ConstraintRep::fetchEventAttribute( const std::string& event_name, unsigned int event_flag)
00077 {
00078 bool flag;
00079 flag = m_ptr->getAttribute(event_name)->getBooleanValue();
00080 if ( flag)
00081 m_eventMask |= event_flag;
00082 }
00083
00084 std::string ConstraintRep::getName() const
00085 {
00086 #if(0)
00087
00088
00089 return m_name;
00090 #else
00091
00092
00093 if( m_ptr) return m_ptr->getName();
00094 else return m_name;
00095 #endif
00096 }
00097
00098 std::string ConstraintRep::getDispName() const
00099 {
00100 return m_description;
00101 }
00102
00103 void ConstraintRep::init( const std::string& name,
00104 int mask, const std::string& depth, int priority,
00105 const std::string& equation, const std::string& disp_name)
00106 {
00107 m_name = name;
00108 m_description = disp_name;
00109
00110 m_equation = equation;
00111 m_priority = priority;
00112 m_depth = depth;
00113 m_eventMask = mask;
00114 }
00115
00116 std::string ConstraintRep::doDump()
00117 {
00118 m_defdForNamesp = m_namespace;
00119 std::string mmm = "";
00120
00121 char mask[64]; sprintf(mask,"%x", m_eventMask);
00122
00123 char priority_str[2]; sprintf( priority_str, "%d", m_priority);
00124 mmm += indStr() + "<constraint name=\"" + m_name + "\" eventmask = \"0x" + std::string(mask) +
00125 "\" depth = \"" + m_depth;
00129 if( !m_defdForNamesp.empty() && m_ptr && m_ptr->isInLibrary()) mmm+= "\" defdfornamesp = \"" + m_defdForNamesp;
00130 mmm += "\" priority = \"" + std::string(priority_str) + "\">\n";
00131
00132 ++ind;
00133 mmm += indStr() + "<![CDATA[" + m_equation + "]]>\n";
00134 mmm += dumpDispName();
00135 --ind;
00136 mmm += indStr() + "</constraint>\n";
00137
00138 return mmm;
00139 }