|
From: <ma...@us...> - 2011-02-09 19:47:07
|
Revision: 1037
http://scstudio.svn.sourceforge.net/scstudio/?rev=1037&view=rev
Author: madzin
Date: 2011-02-09 19:47:01 +0000 (Wed, 09 Feb 2011)
Log Message:
-----------
Change diff interface, set position of new elements in the flow
Modified Paths:
--------------
trunk/src/data/msc.h
trunk/src/membership/diff_impl.cpp
trunk/src/membership/membership_base.h
trunk/tests/diff/diff_test.cpp
Modified: trunk/src/data/msc.h
===================================================================
--- trunk/src/data/msc.h 2011-02-09 11:05:45 UTC (rev 1036)
+++ trunk/src/data/msc.h 2011-02-09 19:47:01 UTC (rev 1037)
@@ -1623,6 +1623,11 @@
void glue_event(const EventPtr& event);
+ Event* get_event()
+ {
+ return m_event;
+ }
+
virtual bool is_glued() const
{
return m_event != NULL;
Modified: trunk/src/membership/diff_impl.cpp
===================================================================
--- trunk/src/membership/diff_impl.cpp 2011-02-09 11:05:45 UTC (rev 1036)
+++ trunk/src/membership/diff_impl.cpp 2011-02-09 19:47:01 UTC (rev 1037)
@@ -58,9 +58,16 @@
* parameters: a - specification
* b - flow
*/
-MscPtr MembershipAlg::diff(MscPtr specification, MscPtr msc_flow)
+MscPtr MembershipAlg::diff(MscPtr specification, std::vector<MscPtr>& msc_flows)
{
- BMscPtr flow = boost::dynamic_pointer_cast<BMsc> (msc_flow);
+ //TODO redirect the output messages
+ if(msc_flows.size() > 1)
+ std::cerr << "Warning: in this version, it is supported for one flow, others is ignored" << std::endl;
+
+ if(msc_flows.size() == 0)
+ std::cerr << "Error: No flow was chosen for checking" << std::endl;
+
+ BMscPtr flow = boost::dynamic_pointer_cast<BMsc> (msc_flows[0]);
if(flow == NULL)
{
@@ -381,7 +388,7 @@
return NULL;
}
-StrictOrderAreaPtr get_proper_area(BMscPtr flow, std::wstring inst_name)
+StrictOrderAreaPtr get_proper_area(BMscPtr flow, Difference* diff, std::wstring inst_name)
{
InstancePtrList instances = flow->get_instances();
InstancePtrList::iterator instances_it;
@@ -396,8 +403,28 @@
StrictOrderAreaPtr s_e_a;
if(instances_it == instances.end())
- {
+ {
+ InstancePtr original;
+
+ CompleteMessagePtr com_msg = boost::dynamic_pointer_cast<CompleteMessage>(diff->getMessage());
+
+ if(com_msg != NULL)
+ {
+ if(diff->getDirection() == SEND)
+ original = com_msg->get_sender();
+ else
+ original = com_msg->get_receiver();
+ }
+ else
+ {
+ IncompleteMessagePtr incom_msg = boost::dynamic_pointer_cast<IncompleteMessage>(diff->getMessage());
+ original = incom_msg->get_event()->get_instance();
+ }
+
InstancePtr inst = new Instance(inst_name);
+ inst->set_line_begin(original->get_line_begin());
+ inst->set_line_end(original->get_line_end());
+
flow->add_instance(inst);
s_e_a = new StrictOrderArea();
s_e_a->set_instance(inst.get());
@@ -419,6 +446,54 @@
return s_e_a;
}
+void set_event_position(StrictEventPtr e, Difference* diff, std::wstring inst_name, BMscPtr flow)
+{
+ InstancePtrList insts = flow->get_instances();
+ InstancePtrList::iterator it;
+ InstancePtr inst = NULL;
+
+ for(it = insts.begin(); it != insts.end(); it++)
+ {
+ if((*it)->get_label() == inst_name)
+ {
+ inst = *it;
+ break;
+ }
+ }
+
+ MscPoint position, start_p, end_p;
+
+ if(inst == NULL)
+ throw std::runtime_error("Error: unexpected behaviour");
+
+ if(diff->getLocation() == NULL)
+ {
+ start_p = inst->get_line_begin();
+
+ StrictOrderAreaPtr s_e_a = boost::dynamic_pointer_cast<StrictOrderArea>(inst->get_first());
+
+ if(s_e_a == NULL || s_e_a->get_first() == NULL)
+ end_p = inst->get_line_end();
+ else
+ end_p = s_e_a->get_first()->get_position();
+ }
+ else
+ {
+ start_p = diff->getLocation()->get_position();
+ StrictEventPtr original_successor = diff->getLocation()->get_successor();
+
+ if(original_successor != NULL)
+ end_p = original_successor->get_position();
+ else
+ end_p = diff->getLocation()->get_instance()->get_line_end();
+ }
+
+ double x = start_p.get_x() + (end_p.get_x() - start_p.get_x())/2;
+ double y = start_p.get_y() + (end_p.get_y() - start_p.get_y())/2;
+ position = MscPoint(x,y);
+ e->set_position(position);
+}
+
/*
* create new event and incomplete message
* then add it to the proper ordering
@@ -426,6 +501,7 @@
void add_incomplete_message(BMscPtr dup_flow, Difference* diff, IncompleteMessagePtr msg, std::wstring ins_name)
{
StrictEventPtr new_e = new StrictEvent();
+ set_event_position(new_e, diff, ins_name, dup_flow);
IncompleteMessagePtr new_msg = new IncompleteMessage(
msg->is_lost() ? LOST : FOUND,
@@ -437,7 +513,7 @@
if(diff->getLocation() != NULL)
diff->getLocation()->set_successor(new_e);
else
- get_proper_area(dup_flow, ins_name)->set_first(new_e);
+ get_proper_area(dup_flow, diff, ins_name)->set_first(new_e);
}
void add_complete_message(BMscPtr dup_flow, Difference* diff, Difference* match_diff,
@@ -447,21 +523,24 @@
StrictEventPtr predecessor1 = diff->getLocation();
StrictEventPtr predecessor2 = match_diff->getLocation();
- StrictEventPtr new_e1 = new StrictEvent();
- StrictEventPtr new_e2 = new StrictEvent();
-
StrictOrderAreaPtr strict_e_a1, strict_e_a2;
if(predecessor1 == NULL)
- strict_e_a1 = get_proper_area(dup_flow, inst_name);
+ strict_e_a1 = get_proper_area(dup_flow, diff, inst_name);
else
strict_e_a1 = predecessor1->get_area();
if(predecessor2 == NULL)
- strict_e_a2 = get_proper_area(dup_flow, match_inst_name);
+ strict_e_a2 = get_proper_area(dup_flow, diff, match_inst_name);
else
strict_e_a2 = predecessor2->get_area();
+ StrictEventPtr new_e1 = new StrictEvent();
+ set_event_position(new_e1, diff, inst_name, dup_flow);
+
+ StrictEventPtr new_e2 = new StrictEvent();
+ set_event_position(new_e2, match_diff, match_inst_name, dup_flow);
+
new_e1->set_area(strict_e_a1.get());
new_e2->set_area(strict_e_a2.get());
Modified: trunk/src/membership/membership_base.h
===================================================================
--- trunk/src/membership/membership_base.h 2011-02-09 11:05:45 UTC (rev 1036)
+++ trunk/src/membership/membership_base.h 2011-02-09 19:47:01 UTC (rev 1037)
@@ -802,7 +802,7 @@
virtual MscPtr find(MscPtr hmsc, MscPtr bmsc);
//! Make diff between specification and flow
- virtual MscPtr diff(MscPtr specification, MscPtr flow);
+ virtual MscPtr diff(MscPtr specification, std::vector<MscPtr>& flows);
//! Finds each bmsc flow from the vector in hmsc specification
virtual MscPtr find(MscPtr hmsc, std::vector<MscPtr>& bmscs);
Modified: trunk/tests/diff/diff_test.cpp
===================================================================
--- trunk/tests/diff/diff_test.cpp 2011-02-09 11:05:45 UTC (rev 1036)
+++ trunk/tests/diff/diff_test.cpp 2011-02-09 19:47:01 UTC (rev 1037)
@@ -100,11 +100,9 @@
MembershipAlg mem;
mem.set_printer(&printer);
- BMscPtr bmsc = boost::dynamic_pointer_cast<BMsc>(msc_b[0]);
-
MscPtr result;
- result = mem.diff(msc[0], bmsc);
+ result = mem.diff(msc[0], msc_b);
if(result == NULL)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|