From: <xf...@us...> - 2012-06-23 11:06:09
|
Revision: 1419 http://scstudio.svn.sourceforge.net/scstudio/?rev=1419&view=rev Author: xfarmad Date: 2012-06-23 11:06:03 +0000 (Sat, 23 Jun 2012) Log Message: ----------- Modified Paths: -------------- branches/exportTexBranch/trunk/src/data/Z120/exportTex.cpp Modified: branches/exportTexBranch/trunk/src/data/Z120/exportTex.cpp =================================================================== --- branches/exportTexBranch/trunk/src/data/Z120/exportTex.cpp 2012-06-23 10:48:45 UTC (rev 1418) +++ branches/exportTexBranch/trunk/src/data/Z120/exportTex.cpp 2012-06-23 11:06:03 UTC (rev 1419) @@ -25,17 +25,17 @@ * * Note: Naming conventions violated for 'code prettiness' reasons. */ -#define VALID_NAME_TEX(name) __VALID_NAME_TEX(this, name) +#define VALID_NAME(name) __VALID_NAME(this, name) -class __VALID_NAME_TEX +class __VALID_NAME { public: - __VALID_NAME_TEX(ExportTex* exportTex, const std::wstring &name) + __VALID_NAME(ExportTex* exportTex, const std::wstring &name) : m_exportTex(exportTex), m_name(name) { } friend std::ostream& - operator<<(std::ostream& os, const __VALID_NAME_TEX& value) + operator<<(std::ostream& os, const __VALID_NAME& value) { static const std::string replacement = "\\_"; bool was_replacement = false; @@ -102,7 +102,6 @@ } - int ExportTex::print_document_head(std::ostream& stream) { stream << "\\documentclass{article}" <<std::endl; @@ -124,7 +123,7 @@ int result = 0; // error count print_document_head(stream); - stream << "\\section*{"<< VALID_NAME_TEX(name) << "}" << std::endl; + stream << "\\section*{"<< VALID_NAME(name) << "}" << std::endl; std::set<std::wstring> printed; @@ -178,63 +177,69 @@ event_level_map.insert( std::make_pair<Coordinate,MscElementPtrList>(coordinate, MscElementPtrList() )); } -void ExportTex::insert_comment(CommentPtr comment,ElementListMap& event_level_map, Coordinate coordinate = 0) +void ExportTex::insert_pointer(MscElementPtr pointer, Coordinate coordinate, ElementListMap& event_level_map) { ElementListMap::iterator it; - Coordinate cor = comment->get_position().get_y()+coordinate; - it = event_level_map.find(cor); - + it = event_level_map.find(coordinate); if(it == event_level_map.end()) { - create_level(cor,event_level_map); - it = event_level_map.find(cor); + create_level(coordinate,event_level_map); + it = event_level_map.find(coordinate); } - - (*it).second.push_back(comment); + (*it).second.push_back(pointer); } +void ExportTex::insert_comment(CommentPtr comment,ElementListMap& event_level_map, Coordinate coordinate = 0) +{ + Coordinate cor = comment->get_position().get_y()+coordinate; + insert_pointer(comment,cor,event_level_map); +} + void ExportTex::insert_event(EventPtr event,ElementListMap& event_level_map, Coordinate coordinate = 0) { - ElementListMap::iterator it; Coordinate cor = event->get_position().get_y()+coordinate; - it = event_level_map.find(cor); - - if(it == event_level_map.end()) - { - create_level(cor,event_level_map); - it = event_level_map.find(cor); - } - + insert_pointer(event,cor,event_level_map); + for(CommentPtrSet::const_iterator cpos = event->get_comments().begin(); cpos != event->get_comments().end(); cpos++) { insert_comment((*cpos),event_level_map); } - - (*it).second.push_back(event); } void ExportTex::insert_coregion_area(CoregionAreaPtr coregion_area,ElementListMap& event_level_map) { - ElementListMap::iterator it; - - it = event_level_map.find(coregion_area->get_begin_height()); - if(it == event_level_map.end()) - { - create_level(coregion_area->get_begin_height(),event_level_map); - it = event_level_map.find(coregion_area->get_begin_height()); - } - (*it).second.push_back(coregion_area); - - it = event_level_map.find(coregion_area->get_end_height()); - if(it == event_level_map.end()) - { - create_level(coregion_area->get_end_height(),event_level_map); - it = event_level_map.find(coregion_area->get_end_height()); - } - (*it).second.push_back(coregion_area); + insert_pointer(coregion_area,coregion_area->get_begin_height(),event_level_map); + insert_pointer(coregion_area,coregion_area->get_end_height(),event_level_map); } +void ExportTex::insert_time_relations(ElementListMap& event_level_map, const EventPtr& event, Coordinate coordinate = 0) +{ + const TimeRelationEventPtrList& relations = event->get_time_relations(); + const AbsoluteTimePtrList absolute_times = event->get_absolut_times(); + // process all absolute time constraints + for(AbsoluteTimePtrList::const_iterator apos = absolute_times.begin(); + apos != absolute_times.end(); apos++) + { + insert_pointer(*apos,(*apos)->get_position().get_y()+coordinate,event_level_map); + } + // process all time relations + for(TimeRelationEventPtrList::const_iterator rpos = relations.begin(); + rpos != relations.end(); rpos++) + { + // for each "event a" we print the time relation to "event b" + // we thus skip all "events b" + if((*rpos)->get_event_a() != event) + continue; + + insert_pointer(*rpos,(*rpos)->get_event_a()->get_position().get_y()+coordinate,event_level_map); + } +} + + + + + #define toCm /10 int ExportTex::save_hmsc(std::ostream& stream, const HMscPtr& hmsc) @@ -288,7 +293,7 @@ } node_stack.clear(); - stream << "\\begin{hmsc}{" << VALID_NAME_TEX(hmsc->get_label()) << "}("; + stream << "\\begin{hmsc}{" << VALID_NAME(hmsc->get_label()) << "}("; if(llCorner.get_x()<0) stream << -(llCorner.get_x()-1)toCm; else @@ -336,7 +341,7 @@ { stream << "\\hmscconnection{" << node_id_map.get_id(*npos) << "}(" << connection_node->get_position().get_x()toCm - << "," << -condition_node->get_position().get_y()toCm << ")" << std::endl; + << "," << -connection_node->get_position().get_y()toCm << ")" << std::endl; } ReferenceNodePtr reference_node = boost::dynamic_pointer_cast<ReferenceNode>(*npos); @@ -345,7 +350,7 @@ if(reference_node->get_msc() != NULL) { stream << "\\hmscreference{" << node_id_map.get_id(*npos) - << "}{" << VALID_NAME_TEX(reference_node->get_msc()->get_label()) + << "}{" << VALID_NAME(reference_node->get_msc()->get_label()) << "}(" << reference_node->get_position().get_x()toCm << "," << -reference_node->get_position().get_y()toCm << ")" << std::endl; m_printing.push_back(reference_node->get_msc()); @@ -402,9 +407,13 @@ SuccessorNode *successor = (*spos)->get_successor(); HMscNode *successor_node = dynamic_cast<HMscNode*>(successor); - - stream << "\\arrow{" << node_id_map.get_id(*npos) << "}{" - << node_id_map.get_id(successor_node) << "}" << std::endl; + + stream << "\\arrow{" << node_id_map.get_id(*npos) << "}["; + for(std::list<MscPoint>::const_iterator point = (*spos)->get_line().get_points().begin(); point != (*spos)->get_line().get_points().end();point++){ + stream << "(" << point->get_x()toCm << "," << point->get_y()toCm << ")"; + } + + stream << "]{" << node_id_map.get_id(successor_node) << "}" << std::endl; // add successors of this node to the stack // note: std::list<>::push_back doesn't invalidate iterators @@ -457,6 +466,7 @@ event != NULL; event = event->get_successor()) { insert_event(event,event_level_map); + insert_time_relations(event_level_map,event); } } @@ -491,6 +501,7 @@ // note: std::list<>::push_back doesn't invalidate iterators push_back_if_unique<CoregionEventPtr>(event_stack, successor); } + insert_time_relations(event_level_map,*epos); } } } @@ -509,7 +520,7 @@ } //print_element_attributes(stream, bmsc); - stream << "\\begin{msc}{" << VALID_NAME_TEX(bmsc->get_label()) << "}" << std::endl; + stream << "\\begin{msc}{" << VALID_NAME(bmsc->get_label()) << "}" << std::endl; print_instances(stream,bmsc->get_instances(),instance_id_map); @@ -583,7 +594,8 @@ void ExportTex::print_event(std::ostream& stream, PtrIDMap<MscMessagePtr>& message_id_map, const EventPtr& event,ElementListMap& event_level_map,PtrIDMap<InstancePtr>& instance_id_map) { - print_event_comment(stream, event,event_level_map,instance_id_map); + print_event_comment(stream, event,event_level_map, instance_id_map); + print_time_relations(stream, event,event_level_map, instance_id_map); CompleteMessagePtr complete_message = event->get_complete_message(); if(complete_message != NULL) { @@ -605,29 +617,38 @@ } - stream << "\\mess{" << VALID_NAME_TEX(complete_message->get_label()) - << "}{"<< instance_id_map.get_id(complete_message->get_sender()) << "_" << VALID_NAME_TEX(complete_message->get_sender()->get_label()) - << "}[0.2]{"<< instance_id_map.get_id(complete_message->get_receiver()) << "_" << VALID_NAME_TEX(complete_message->get_receiver()->get_label()) + stream << "\\mess{" << VALID_NAME(complete_message->get_label()) + << "}{"<< instance_id_map.get_id(complete_message->get_sender()) << "_" << VALID_NAME(complete_message->get_sender()->get_label()) + << "}[0.2]{"<< instance_id_map.get_id(complete_message->get_receiver()) << "_" << VALID_NAME(complete_message->get_receiver()->get_label()) << "}[" << get_slope(event_level_map.find(sendY),event_level_map.find(receiveY),event_level_map) << "]" << std::endl; } } - IncompleteMessagePtr incomplete_message = event->get_incomplete_message(); - if(incomplete_message != NULL) + + LocalActionPtr localAction = boost::dynamic_pointer_cast<LocalAction>(event->get_incomplete_message()); + if(localAction!=NULL){ + stream << "localAction" << std::endl; + } + else { - stream << "\\setlength{\\selfmesswidth}{" << fabs(incomplete_message->get_dot_position().get_x() - event->get_instance()->get_line_begin().get_x() ) << "mm}" << std::endl; + IncompleteMessagePtr incomplete_message = event->get_incomplete_message(); + if(incomplete_message != NULL) + { + + stream << "\\setlength{\\selfmesswidth}{" << fabs(incomplete_message->get_dot_position().get_x() - event->get_instance()->get_line_begin().get_x() ) << "mm}" << std::endl; - if(incomplete_message->is_lost()) - stream << "\\lost"; - if(incomplete_message->is_found()) - stream << "\\found"; - if(incomplete_message->get_dot_position().get_x()> event->get_instance()->get_line_begin().get_x()) - stream << "[r]"; - stream << "{" << VALID_NAME_TEX(incomplete_message->get_label()) - << "}{}{" << instance_id_map.get_id(event->get_instance()) << "_" << VALID_NAME_TEX(event->get_instance()->get_label()) - << "}" << std::endl; - } + if(incomplete_message->is_lost()) + stream << "\\lost"; + if(incomplete_message->is_found()) + stream << "\\found"; + if(incomplete_message->get_dot_position().get_x()> event->get_instance()->get_line_begin().get_x()) + stream << "[r]"; + stream << "{" << VALID_NAME(incomplete_message->get_label()) + << "}{}{" << instance_id_map.get_id(event->get_instance()) << "_" << VALID_NAME(event->get_instance()->get_label()) + << "}" << std::endl; + } + } } void ExportTex::print_coregion_area(std::ostream& stream,PtrIDMap<InstancePtr>& instance_id_map, const CoregionAreaPtr& coregionArea, Coordinate coordinate) @@ -636,14 +657,14 @@ { stream << "\\setlength{\\regionbarwidth}{" << coregionArea->get_width() << "mm}" << std::endl; stream << "\\regionstart{coregion}{" - << instance_id_map.get_id(coregionArea->get_instance()) << "_" << VALID_NAME_TEX(coregionArea->get_instance()->get_label()) <<"}" << std::endl; + << instance_id_map.get_id(coregionArea->get_instance()) << "_" << VALID_NAME(coregionArea->get_instance()->get_label()) <<"}" << std::endl; return; } if(coregionArea->get_end_height() == coordinate) { stream << "\\regionend{" - << instance_id_map.get_id(coregionArea->get_instance()) << "_" << VALID_NAME_TEX(coregionArea->get_instance()->get_label()) <<"}" << std::endl; + << instance_id_map.get_id(coregionArea->get_instance()) << "_" << VALID_NAME(coregionArea->get_instance()->get_label()) <<"}" << std::endl; return; } } @@ -658,8 +679,8 @@ stream << "\\msccomment"; if((*cpos)->get_position().get_x() > event->get_instance()->get_line_begin().get_x()) stream << "[r]"; - stream << "{" << VALID_NAME_TEX((*cpos)->get_text()) << "}{" - << instance_id_map.get_id(event->get_instance()) << "_" << VALID_NAME_TEX(event->get_instance()->get_label()) << "}"; + stream << "{" << VALID_NAME((*cpos)->get_text()) << "}{" + << instance_id_map.get_id(event->get_instance()) << "_" << VALID_NAME(event->get_instance()->get_label()) << "}"; stream << "[" << get_slope(event_level_map.find(event->get_position().get_y()),event_level_map.find((*cpos)->get_position().get_y()),event_level_map) << "]"; stream << std::endl; } @@ -678,8 +699,95 @@ } stream << "\\setlength{\\instwidth}{" << (*min)->get_width() << "mm}" << std::endl; stream << "\\declinst{" << instance_id_map.get_id((*min)) << "_" - << VALID_NAME_TEX((*min)->get_label()) << "}{" - << VALID_NAME_TEX((*min)->get_label()) << "}{}" << std::endl; + << VALID_NAME((*min)->get_label()) << "}{" + << VALID_NAME((*min)->get_label()) << "}{}" << std::endl; instances.erase(min); } +} + +void ExportTex::print_absolute_time(std::ostream& stream, AbsoluteTimePtr abs) +{ + const std::list< MscTimeInterval<double> > constraints = abs->get_interval_set().get_set(); + + // NOTE: using the output ordering just for sure, in real, just one interval is present + BasicStringListPrinter<double> printer; + + for(std::list< MscTimeInterval<double> >::const_iterator it = constraints.begin(); + it != constraints.end(); it++) + { + if(it->get_begin_value() != it->get_end_value()) + { + if (it->get_begin_closed()) + printer << "@["; + else + printer << "@("; + + printer << it->get_begin() << "," << it->get_end(); + + if (it->get_end_closed()) + printer << "]"; + else + printer << ")"; + } + else + printer << "[@" << it->get_begin() << "]"; + + printer.commit_item(it->get_begin().get_value()); + } + + printer.print(stream); +} + +void ExportTex::print_time_relations(std::ostream& stream, const EventPtr& event,ElementListMap& event_level_map,PtrIDMap<InstancePtr>& instance_id_map) +{ + + const TimeRelationEventPtrList& relations = event->get_time_relations(); + const AbsoluteTimePtrList absolute_times = event->get_absolut_times(); + // process all absolute time constraints + for(AbsoluteTimePtrList::const_iterator apos = absolute_times.begin(); + apos != absolute_times.end(); apos++) + { + stream << "\\mscmark["; + if(get_slope(event_level_map.find(event->get_position().get_y()),event_level_map.find((*apos)->get_position().get_y()),event_level_map)<0) + { + stream << "b"; + } + else + { + stream << "t"; + } + if(((*apos)->get_position().get_x() - event->get_instance()->get_line_begin().get_x() )>0) + { + stream << "r"; + } + else + { + stream << "l"; + } + stream << "]{"; + print_absolute_time(stream, *apos); + stream << "}{" << VALID_NAME(event->get_instance()->get_label()) << "}" << std::endl; + } + + // process all time relations + for(TimeRelationEventPtrList::const_iterator rpos = relations.begin(); + rpos != relations.end(); rpos++) + { + if((*rpos)->get_event_a()==event){ + //TODO: directed interval + stream << "\\measure["; + if((*rpos)->get_width()<0) + { + stream << "r"; + } + else + { + stream << "l"; + } + stream << "]{" << (*rpos)->get_label() << "}{" << (*rpos)->get_event_a()->get_instance()->get_label() + << "}{" << (*rpos)->get_event_b()->get_instance()->get_label() << "}[" + << get_slope(event_level_map.find((*rpos)->get_event_a()->get_position().get_y()),event_level_map.find((*rpos)->get_event_b()->get_position().get_y()),event_level_map) + << "]" << std::endl; + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |