~ubuntu-branches/ubuntu/utopic/gnome-chemistry-utils/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/gcp/mesomery.cc

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-05-10 21:30:51 UTC
  • mfrom: (1.1.15) (2.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20130510213051-mswxsp3vitsgqspm
Tags: 0.14.2-1ubuntu1
* Sync with Debian. Remaining change:
  - Build-depend on firefox-dev instead of xulrunner-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// -*- C++ -*-
2
2
 
3
 
/* 
 
3
/*
4
4
 * GChemPaint library
5
 
 * mesomery.cc 
6
 
 *
7
 
 * Copyright (C) 2002-2010 Jean Bréfort <jean.brefort@normalesup.org>
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or 
10
 
 * modify it under the terms of the GNU General Public License as 
11
 
 * published by the Free Software Foundation; either version 2 of the
 
5
 * mesomery.cc
 
6
 *
 
7
 * Copyright (C) 2002-2011 Jean Bréfort <jean.brefort@normalesup.org>
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU General Public License as
 
11
 * published by the Free Software Foundation; either version 3 of the
12
12
 * License, or (at your option) any later version.
13
13
 *
14
14
 * This program is distributed in the hope that it will be useful,
27
27
#include "mesomer.h"
28
28
#include "mesomery.h"
29
29
#include "mesomery-arrow.h"
 
30
#include <brackets.h>
30
31
#include "molecule.h"
31
32
#include "theme.h"
32
33
#include "view.h"
33
34
#include "widgetdata.h"
 
35
#include <gcugtk/ui-manager.h>
34
36
#include <glib/gi18n-lib.h>
35
37
#include <set>
36
38
#include <cmath>
55
57
        MesomeryArrow *arrow;
56
58
        Document *pDoc = reinterpret_cast<Document *> (GetDocument ());
57
59
        Operation *pOp = pDoc->GetCurrentOperation ();
58
 
        while ((pObj = GetFirstChild (i))) {
 
60
        while ((pObj = GetFirstChild (i))) {            
59
61
                if (pObj->GetType () == MesomeryArrowType) {
60
62
                        arrow = reinterpret_cast<MesomeryArrow*> (pObj);
61
63
                        arrow->SetStartMesomer (NULL);
63
65
                        arrow->SetParent (GetParent ());
64
66
                        if (pOp)
65
67
                                pOp->AddObject (arrow, 1);
66
 
                        
 
68
 
67
69
                } else
68
70
                        delete pObj;
69
71
        }
111
113
                arrows.pop_back ();
112
114
        }
113
115
        Lock (false);
 
116
        GetDocument ()->ObjectLoaded (this);
114
117
        return true;
115
118
}
116
119
 
121
124
        Mesomer *mes;
122
125
} ObjectData;
123
126
 
124
 
bool Mesomery::Build (list<Object*>& Children) throw (invalid_argument)
 
127
bool Mesomery::Build (std::set < Object * > const &Children) throw (invalid_argument)
125
128
{
126
129
        Document *pDoc = dynamic_cast<Document *> (GetDocument ());
127
130
        Theme *pTheme = pDoc->GetTheme ();
128
131
        WidgetData  *pData= reinterpret_cast<WidgetData *> (g_object_get_data (G_OBJECT (pDoc->GetWidget ()), "data"));
129
 
        list<Object *>::iterator i, iend = Children.end ();
130
 
        map<Object *, ObjectData> Objects;
131
 
        list <Object *> Arrows, Trash;
 
132
        set < Object * >::iterator i, iend = Children.end ();
 
133
        map< Object *, ObjectData > Objects;
 
134
        list < Object * > Arrows, Trash;
132
135
        double minright, minleft, x, y, x0, y0, x1, y1, l, d, ps;
133
136
        Object *Left, *Right;
134
137
        ObjectData od;
256
259
        return true;
257
260
}
258
261
 
259
 
static void BuildConnectivity ( set<Object *> &Objects, Mesomer* pMesomer)
 
262
static void BuildConnectivity (set<Object *> &Objects, Mesomer* pMesomer)
260
263
{
261
264
        map<Mesomer *, MesomeryArrow *> *Arrows = pMesomer->GetArrows ();
262
265
        map<Mesomer *, MesomeryArrow *>::iterator i, end = Arrows->end ();
272
275
bool Mesomery::Validate (bool split)
273
276
{
274
277
        map<string, Object*>::iterator i;
 
278
        int other_children = 0;
275
279
        Object *pObj = GetFirstChild (i);
276
 
        while (pObj && pObj->GetType () != MesomerType)
 
280
        while (pObj && pObj->GetType () != MesomerType) {
 
281
                if (pObj->GetType () == BracketsType)
 
282
                        other_children++;
277
283
                pObj = GetNextChild (i);
 
284
        }
278
285
        if (pObj == NULL)
279
286
                return false;
280
287
        set<Object *> Objects;
281
288
        Objects.insert (pObj);
282
289
        BuildConnectivity (Objects, reinterpret_cast<Mesomer *> (pObj));
283
 
        while (Objects.size () < GetChildrenNumber ()) {
 
290
        while (Objects.size () + other_children < GetChildrenNumber ()) {
284
291
                if (!split)
285
292
                        return 2;
286
293
                pObj = GetFirstChild (i);
287
294
                while (pObj && (pObj->GetType () != MesomerType))
288
295
                        pObj = GetNextChild (i);
289
296
                if (reinterpret_cast<Mesomer *> (pObj)->Validate ()) {
290
 
                        Mesomery *ms = new Mesomery (GetParent (), 
 
297
                        Mesomery *ms = new Mesomery (GetParent (),
291
298
                                                                reinterpret_cast<Mesomer *> (pObj));
292
299
                        Document *pDoc = reinterpret_cast<Document*> (GetDocument ());
293
300
                        Operation *pOp = pDoc->GetCurrentOperation ();
526
533
        View *pView = pDoc->GetView ();
527
534
        Theme *pTheme = pDoc->GetTheme ();
528
535
        WidgetData  *pData = reinterpret_cast <WidgetData *> (g_object_get_data (G_OBJECT (pDoc->GetWidget ()), "data"));
529
 
        /* Update the canvas if necessary */
530
 
/*      GnomeCanvas* w = GNOME_CANVAS (((Document*) GetDocument ())->GetWidget ());
531
 
        while (w->idle_id)
532
 
                gtk_main_iteration();
533
 
        gnome_canvas_update_now (w);*/
534
536
        map<string, Object*>::iterator i;
535
537
        Object *pObj = GetFirstChild (i);
536
538
        Mesomer *pStart = NULL, *mes0, *mes;
742
744
        pView->Update (this);
743
745
}
744
746
 
745
 
/* Transform2D is just here to inhibit rotation of retrosynthesis while we do not have 
 
747
/* Transform2D is just here to inhibit rotation of retrosynthesis while we do not have
746
748
real 2D alignment (only vertical at the moment */
747
749
void Mesomery::Transform2D (G_GNUC_UNUSED Matrix2D& m, G_GNUC_UNUSED double x, G_GNUC_UNUSED double y)
748
750
{
751
753
bool Mesomery::OnSignal (G_GNUC_UNUSED SignalId Signal, G_GNUC_UNUSED Object *Child)
752
754
{
753
755
        Validate (true);
754
 
        if (GetChildrenNumber () < 3)
 
756
        if (GetChildrenNumber () < 3 || !Validate (true))
755
757
                delete this;
756
758
        else
757
759
                Align ();
770
772
        pDoc->FinishOperation ();
771
773
}
772
774
 
773
 
bool Mesomery::BuildContextualMenu (GtkUIManager *UIManager, Object *object, double x, double y)
 
775
bool Mesomery::BuildContextualMenu (gcu::UIManager *UIManager, Object *object, double x, double y)
774
776
{
 
777
        if (GetParentOfType (gcu::ReactionType) != NULL)
 
778
                return false;
 
779
        GtkUIManager *uim = static_cast < gcugtk::UIManager * > (UIManager)->GetUIManager ();
775
780
        GtkActionGroup *group = gtk_action_group_new ("mesomery");
776
781
        GtkAction *action = gtk_action_new ("destroy-ms", _("Destroy the mesomery relationship"), NULL, NULL);
777
782
        gtk_action_group_add_action (group, action);
778
783
        g_object_unref (action);
779
 
        gtk_ui_manager_insert_action_group (UIManager, group, 0);
 
784
        gtk_ui_manager_insert_action_group (uim, group, 0);
780
785
        g_object_unref (group);
781
786
        char buf[] = "<ui><popup><menuitem action='destroy-ms'/></popup></ui>";
782
 
        gtk_ui_manager_add_ui_from_string (UIManager, buf, -1, NULL);
783
 
        GtkWidget *w = gtk_ui_manager_get_widget (UIManager, "/popup/destroy-ms");
 
787
        gtk_ui_manager_add_ui_from_string (uim, buf, -1, NULL);
 
788
        GtkWidget *w = gtk_ui_manager_get_widget (uim, "/popup/destroy-ms");
784
789
        g_signal_connect_swapped (w, "activate", G_CALLBACK (do_destroy_mesomery), this);
785
790
        GetParent ()->BuildContextualMenu (UIManager, object, x, y);
786
791
        return true;
808
813
        while (pObj) {
809
814
                if (pObj->GetType () == MesomerType)
810
815
                        if ((new_y = pObj->GetYAlign ()) < y)
811
 
                                y = new_y;                      
 
816
                                y = new_y;
812
817
                pObj = GetNextChild (i);
813
818
        }
814
819
        return y;