/* * MathPlanner 3.0 - Mathematical design tool. * Copyright(C) 2002 Jarmo Nikkanen * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation. * * You should have received a copy of the GNU General Public License with this program. * */ #include "Operators.h" #include "AppControl.h" #include "Error.h" #include "Function_object.h" #include "ConfigReader.h" #include "Datastore.h" #include "Object_string.h" #include "Extern.h" math_node minmax_object::Calculate() { math_node a,b; a=Inner->Calculate(); b=Outer->Calculate(); if (a.type==MN_REAL && b.type==MN_REAL) { if (Opr==0) if (a.mpl.m.Rb.mpl.m.R) value=a; else value=b; } else { Error_flag=true; AppControl->AddError(QObject::tr("Only Real numbers are supported")); } return(value); } void minmax_object::Build() { Inner->Build(); Outer->Build(); } void minmax_object::Reset() { m_base_object::Reset(); StrLo.Init(AppControl); StrLoB.Init(AppControl); PoLoA.Init(AppControl); PoLoB.Init(AppControl); ParLo.Init(AppControl); AssignLo.Init(AppControl); } void minmax_object::Init() { Inner->SetFocus(); } void minmax_object::SendCall(int i) { Inner->SendCall(i); Outer->SendCall(i); } void minmax_object::SetFontSize(int i) { Inner->SetFontSize(i); Outer->SetFontSize(i); } void minmax_object::SeekObject(QPoint p) { if (Inner->Bounds().Rect().contains(p)) { Inner->SeekObject(p); return; } if (Outer->Bounds().Rect().contains(p)) { Outer->SeekObject(p); return; } SetFocus(); } bool minmax_object::AutoDeletion() { if (Inner->IsEmpty() && Inner->HasFocus()==false && Outer->IsEmpty() && Outer->HasFocus()==false && HasFocus()==false) return(true); return(false); } minmax_object::minmax_object(DataStorage *msg) :m_base_object(msg) { Reset(); DataStorage *ar; Type=OT_MINMAX_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; Opr=msg->ReadInt("mm:type"); if (Opr==0) strcpy(Opr_Str_C,"Min"); if (Opr==1) strcpy(Opr_Str_C,"Max"); ar=new DataStorage(); msg->ReadDataStorage("mm:Inner",ar); Inner=new string_object(ar,AppControl,function); delete ar; ar=new DataStorage(); msg->ReadDataStorage("mm:Outer",ar); Outer=new string_object(ar,AppControl,function); delete ar; function->AddString(Inner); Inner->SetParent(this); function->AddString(Outer); Outer->SetParent(this); Bug("parenthesis unarchived"); } DataStorage *minmax_object::BuildStorage() { DataStorage *msg=m_base_object::BuildStorage(); msg->AddInt("mm:type",Opr); DataStorage *ar=Inner->BuildStorage(); msg->AddDataStorage("mm:Inner",ar); delete ar; ar=Outer->BuildStorage(); msg->AddDataStorage("mm:Outer",ar); delete ar; return(msg); } minmax_object::minmax_object(int type,ApplicationControl *a,m_function_object *o,class string_object *str) :m_base_object(a,o,str) { Reset(); Inner=new string_object(10,AppControl,function); Outer=new string_object(10,AppControl,function); if (type==0) Opr=0,strcpy(Opr_Str_C,"Min"); if (type==1) Opr=1,strcpy(Opr_Str_C,"Max"); Type=OT_MINMAX_OBJECT; MainType=OMT_OPERATOR; SubObject=SUB_NONE; Priority=PRIORITY_NONE; function->AddString(Inner); Inner->SetParent(this); function->AddString(Outer); Outer->SetParent(this); } minmax_object::~minmax_object() { delete Inner; delete Outer; } void minmax_object::CalculateBounds() { int cl; cl=AppControl->CenterLine(string); Inner->CalculateBounds(); Outer->CalculateBounds(); StrLo.SetSize(0,Inner->Bounds()); StrLo.SetSize(1,PoLoA.GetOuterRect(string->GetFont(FONT_TYPE_NORMAL),",")); StrLo.SetSize(2,Outer->Bounds()); ParLo.SetSize(StrLo.GetOuterRect(3),0); StrLoB.SetSize(0,AssignLo.GetOuterRect(string->GetFont(FONT_TYPE_NORMAL),Opr_Str_C)); StrLoB.SetSize(1,ParLo.GetOuterRect(cl,0)); bounds=StrLoB.GetOuterRect(2); } void minmax_object::MoveTo(QPoint p) { bounds.SetPosition(p); StrLoB.SetPosition(p); ParLo.SetPosition(StrLoB.GetPosition(1)); StrLo.SetPosition(ParLo.GetPosition()); Inner->MoveTo(StrLo.GetPosition(0)); PoLoA.SetPosition(StrLo.GetPosition(1)); Outer->MoveTo(StrLo.GetPosition(2)); AssignLo.SetPosition(StrLoB.GetPosition(0)); } void minmax_object::Draw(QPainter *paint) { paint->setPen(AppControl->GetColor(FONT_TYPE_OPERATOR)); paint->setFont(string->GetFont(FONT_TYPE_OPERATOR)); ParLo.Draw(paint); AssignLo.Draw(paint); paint->setPen(AppControl->GetColor(FONT_TYPE_NORMAL)); PoLoA.Draw(paint); Inner->Draw(paint); Outer->Draw(paint); if (HasFocus() && function->HasFocus()) { paint->setPen(focus_pen); paint->drawRect(bounds.Rect()); } if (Error_flag && !HasFocus()) { paint->setPen(error_pen); paint->drawRect(bounds.Rect()); } } void minmax_object::FocusNextObject() { if (curr<=0) curr=1,Inner->SetFocus(); else if (curr>=1) curr=0,Outer->SetFocus(); } void minmax_object::KeyReceived(key_code key) { if (key.code==Qt::Key_Down || key.code==Qt::Key_Up) { if (HasFocus()==true && key.code==Qt::Key_Down) Inner->SetFocus(); if (HasFocus()==true && key.code==Qt::Key_Up) Outer->SetFocus(); } else KeyFeedback(key); } void minmax_object::KeyFeedback(key_code key) { key.insert_mode=MODE_AUTO; KeyOutput(key); } void minmax_object::MessageReceived(DataStorage *msg,int rec) { if (rec==TO_OPERATOR) { if (ISMSG(MSG_DATA)) { Opr=msg->ReadInt("Oper"); if (Opr==0) strcpy(Opr_Str_C,"Min"); if (Opr==1) strcpy(Opr_Str_C,"Max"); } } } base_object_message *minmax_object::CreateControlObject() { Bug("########### minmax_mes created"); return(new minmax_mes(AppControl)); } minmax_mes::minmax_mes(ApplicationControl *a) :base_object_message(a) { hbox=new QHBox(); combo=new QComboBox(hbox); combo->insertItem(QString("Min")); combo->insertItem(QString("Max")); connect(combo,SIGNAL(activated(int)),this,SLOT(Combo(int))); } minmax_mes::~minmax_mes() { delete combo; delete hbox; } QWidget *minmax_mes::MainWidget() { return(hbox); } void minmax_mes::Combo(int index) { DataStorage *msg=MESSAGE(MSG_DATA); msg->AddInt("Oper",index); PostMessage(msg,TO_OPERATOR); }