File: render_common.h

package info (click to toggle)
indigo 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 48,936 kB
  • sloc: ansic: 332,816; cpp: 169,470; python: 20,033; java: 13,701; cs: 9,979; asm: 8,475; sql: 6,743; xml: 6,354; javascript: 1,245; sh: 555; php: 506; makefile: 54
file content (587 lines) | stat: -rw-r--r-- 16,502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
/****************************************************************************
 * Copyright (C) from 2009 to Present EPAM Systems.
 *
 * This file is part of Indigo toolkit.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ***************************************************************************/

#ifndef __render_common_h__
#define __render_common_h__

#include "base_cpp/tlscont.h"
#include "graph/graph.h"
#include "layout/metalayout.h"
#include "molecule/elements.h"
#include "reaction/base_reaction.h"
#include "render2d/render_cdxml.h"

typedef void* PVOID;

namespace indigo
{

    struct Vec2f;
    struct Edge;
    class BaseMolecule;
    class BaseReaction;
    class BaseMolecule;
    class Reaction;
    class QueryMolecule;
    class QueryReaction;
    class Output;

    enum DINGO_MODE
    {
        MODE_NONE,
        MODE_PDF,
        MODE_PNG,
        MODE_SVG,
        MODE_EMF,
        MODE_HDC,
        MODE_PRN,
        MODE_CDXML
    };
    enum LABEL_MODE
    {
        LABEL_MODE_NONE,
        LABEL_MODE_HETERO,
        LABEL_MODE_TERMINAL_HETERO,
        LABEL_MODE_ALL
    };
    enum STEREO_STYLE
    {
        STEREO_STYLE_EXT,
        STEREO_STYLE_OLD,
        STEREO_STYLE_NONE
    };
    enum
    {
        CWC_BASE = -2,
        CWC_WHITE = 0,
        CWC_BLACK,
        CWC_RED,
        CWC_GREEN,
        CWC_BLUE,
        CWC_DARKGREEN,
        CWC_COUNT
    };
    enum FONT_SIZE
    {
        FONT_SIZE_LABEL = 0,
        FONT_SIZE_ATTR,
        FONT_SIZE_RGROUP_LOGIC,
        FONT_SIZE_RGROUP_LOGIC_INDEX,
        FONT_SIZE_INDICES,
        FONT_SIZE_ATTACHMENT_POINT_INDEX,
        FONT_SIZE_RSITE_ATTACHMENT_INDEX,
        FONT_SIZE_COMMENT,
        FONT_SIZE_TITLE,
        FONT_SIZE_DATA_SGROUP,
        FONT_SIZE_COUNT /*must be the last*/
    };
    enum COMMENT_POS
    {
        COMMENT_POS_TOP,
        COMMENT_POS_BOTTOM
    };
    enum HYDRO_POS
    {
        HYDRO_POS_RIGHT = 0,
        HYDRO_POS_UP,
        HYDRO_POS_DOWN,
        HYDRO_POS_LEFT
    };

    // cos(a) to cos(a/2)
    double cos2c(const double cs);
    // cos(a) to sin(a/2)
    double sin2c(const double cs);
    // cos(a) to tg(a/2)
    double tg2c(const double cs);
    // cos(a) to ctg(a/2)
    double ctg2c(const double cs);

    struct RenderItem
    {
        enum TYPE
        {
            RIT_NULL = 0,
            RIT_LABEL,
            RIT_PSEUDO,
            RIT_HYDROGEN,
            RIT_HYDROINDEX,
            RIT_ISOTOPE,
            RIT_CHARGESIGN,
            RIT_CHARGEVAL,
            RIT_RADICAL,
            RIT_STEREOGROUP,
            RIT_VALENCE,
            RIT_AAM,
            RIT_CHIRAL,
            RIT_ATTACHMENTPOINT,
            RIT_ATOMID,
            RIT_TOPOLOGY,
            RIT_SGROUP,
            RIT_DATASGROUP,
            RIT_COMMENT,
            RIT_TITLE
        };

        RenderItem();
        void clear();

        TYPE ritype;
        Vec2f bbp;    // a point to draw the text from
        Vec2f bbsz;   // width and height of the text
        Vec2f relpos; // text bearing (positive if text is entirely on the
                      // right and bottom from the bbp point)
        int color;
        bool highlighted;
        bool noBondOffset;
    };

    struct TextItem : public RenderItem
    {
        TextItem()
        {
            clear();
        }
        void clear();
        Array<char> text;
        FONT_SIZE fontsize;
    };

    struct GraphItem : public RenderItem
    {
        enum TYPE
        {
            DOT,
            CAP,
            PLUS,
            MINUS
        };
        GraphItem()
        {
            clear();
        }
        void clear();
        TYPE type;
    };

    struct RenderItemBracket : public RenderItem
    {
        RenderItemBracket()
        {
            clear();
        }
        void clear();
        Vec2f p0, p1, q0, q1, d, n;
        float width, length;
        bool invertUpperLowerIndex;
    };

    struct RenderItemAttachmentPoint : public RenderItem
    {
        RenderItemAttachmentPoint()
        {
            clear();
        }
        void clear();
        int number;
        Vec2f p0, p1, dir;
    };

    struct RenderItemRSiteAttachmentIndex : public RenderItem
    {
        RenderItemRSiteAttachmentIndex()
        {
            clear();
        }
        void clear();
        int number;
        float radius;
    };

    struct AtomDesc
    {
        enum TYPE
        {
            TYPE_REGULAR,
            TYPE_PSEUDO,
            TYPE_QUERY
        };
        AtomDesc();
        void clear();

        int tibegin, ticount;
        int gibegin, gicount;
        int attachmentPointBegin, attachmentPointCount;
        int rSiteAttachmentIndexBegin, rSiteAttachmentIndexCount;

        int type;
        bool showLabel;
        bool showHydro;
        HYDRO_POS hydroPos;
        bool isRGroupAttachmentPoint;
        bool fixed;
        bool exactChange;
        bool pseudoAtomStringVerbose;
        Vec2f pos;
        Vec2f boundBoxMin;
        Vec2f boundBoxMax;
        Vec3f hcolor;
        bool hcolorSet;
        int label;
        int queryLabel;
        int color;
        int stereoGroupType;
        int stereoGroupNumber;
        int implicit_h;
        Array<int> list;
        Array<char> pseudo;
        Array<int> nearbyAtoms;
        int aam;
        int inversion;
        float implHPosWeights[4];
        float upperSin, lowerSin, rightSin, leftSin;

        float leftMargin, rightMargin, ypos, height;

    private:
        AtomDesc(const AtomDesc& ad);
    };

    struct Sgroup
    {
        Sgroup();
        void clear();

        int tibegin, ticount;
        int gibegin, gicount;
        int bibegin, bicount;

    private:
        Sgroup(const SGroup& sg);
    };

    struct BondEnd
    {
        BondEnd();
        void clear();

        Vec2f dir;
        Vec2f lnorm;
        Vec2f p; // corrected position
        float rcos;
        float rsin;

        // these are bond end ids in the _data.bondend array, NOT neighbor indices in the molecule!
        int rnei;
        int lnei;

        float rang;
        float lcos;
        float lsin;
        int next;
        float lang;
        bool centered;
        int aid;
        int bid;
        float offset;
        bool prolong;
        int lRing;
        float width;

    private:
        BondEnd(const BondEnd& be);
    };

    struct BondDescr : public Edge
    {
        BondDescr();

        DECL_ERROR;

        void clear();

        int getBondEnd(int aid) const;

        Vec2f norm, dir, vb, ve, center;
        float thickness;
        float bahs, eahs;

        bool inRing;
        bool aromRing;
        bool stereoCare;
        bool centered;
        bool lineOnTheRight;
        bool isShort;
        int stereodir;
        bool cistrans;
        int type;
        int queryType;
        float length;
        int be1, be2;
        float extP, extN;
        int tiTopology;
        int topology;
        int reactingCenter;

    private:
        BondDescr(const BondDescr& bd);
    };

    struct Ring
    {
        Ring();
        void clear();

        Array<int> bondEnds;
        Array<float> angles;
        int dblBondCount;
        bool aromatic;
        Vec2f center;
        float radius;

    private:
        Ring(const Ring& r);
    };

    struct MoleculeRenderData
    {
        MoleculeRenderData();
        void clear();

        ObjArray<Sgroup> sgroups;
        ObjArray<AtomDesc> atoms;
        ObjArray<BondDescr> bonds;
        ObjArray<Ring> rings;
        ObjArray<BondEnd> bondends;
        ObjArray<TextItem> textitems;
        ObjArray<GraphItem> graphitems;
        ObjArray<RenderItemAttachmentPoint> attachmentPoints;
        ObjArray<RenderItemRSiteAttachmentIndex> rSiteAttachmentIndices;
        ObjArray<RenderItemBracket> brackets;
        Array<int> aam;
        Array<int> reactingCenters;
        Array<int> inversions;
        Array<int> exactChanges;

    private:
        MoleculeRenderData(const MoleculeRenderData& data);
    };

    class RenderSettings
    {
    public:
        RenderSettings();
        void init(float sf, float lwf);

        CP_DECL;
        TL_CP_DECL(Array<double>, bondDashAromatic);
        TL_CP_DECL(Array<double>, bondDashAny);
        TL_CP_DECL(Array<double>, bondDashSingleOrAromatic);
        TL_CP_DECL(Array<double>, bondDashDoubleOrAromatic);

        float labelInternalOffset;
        float lowerIndexShift;
        float unit;
        float bondLineWidth;
        float bondSpace;
        float boundExtent;
        float upperIndexShift;
        float radicalRightOffset;
        float radicalRightVertShift;
        float radicalTopOffset;
        float radicalTopDistDot;
        float radicalTopDistCap;
        float stereoGroupLabelOffset;
        float dashUnit;
        float eps;
        float stereoCareBoxSize;
        float cosineTreshold;
        float prolongAdjSinTreshold;
        float minBondLength;
        float graphItemDotRadius;
        float graphItemCapSlope;
        float graphItemCapBase;
        float graphItemCapWidth;
        float graphItemDigitWidth;
        float graphItemDigitHeight;
        float graphItemSignLineWidth;
        float graphItemPlusEdge;

        float fzz[FONT_SIZE_COUNT];

        // Layout params, relative to average bond length units
        float layoutMarginHorizontal;
        float layoutMarginVertical;
        float plusSize;
        float metaLineWidth;
        float arrowLength;
        float arrowHeadWidth;
        float arrowHeadSize;
        float equalityInterval;
        float rGroupIfThenInterval;
        float neighboringLabelTolerance;
        float minSin;
        float neighboringAtomDistanceTresholdA;
        float neighboringAtomDistanceTresholdB;

    private:
        RenderSettings(const RenderSettings& settings);
    };

    struct MultilineTextLayout
    {
        enum Alignment
        {
            Left,
            Right,
            Center
        };

        MultilineTextLayout();
        MultilineTextLayout(Alignment bbox, Alignment inbox);

        // Text can be aligned in different ways: left, right, center. But if text has multiple
        // lines then this lines can also be aligned in different ways relative to each other
        // +-----------------------------------+--------------+
        // | View                              | Type         |
        // +===================================+==============+
        // | Line                              | left         |
        // | Quite Long line                   |              |
        // +-----------------------------------+--------------+
        // |                              Line | right        |
        // |                   Quite Long line |              |
        // +-----------------------------------+--------------+
        // |               Line                | center       |
        // |         Quite a Long line         |              |
        // +-----------------------------------+--------------+
        // |         Line                      | center-left  |
        // |         Quite a Long line         |              |
        // +-----------------------------------+--------------+

        // Alignment of the bounding box
        Alignment bbox_alignment;
        // Text alignment insdie bounding box
        Alignment inbox_alignment;

        void clear();

        // Returns values from 0.0 to 1.0 depending on the title box alignment
        float getBboxRelativeOffset() const;
        float getInboxRelativeOffset() const;
        static float getRelativeOffset(Alignment alignment);

        float getAnchorPoint(float area_x, float area_width, float text_width);
    };

    struct CanvasOptions
    {
        CanvasOptions();
        void clear();

        int width;
        int height;
        int maxWidth;
        int maxHeight;
        int xOffset;
        int yOffset;
        float bondLength;
        int gridMarginX;
        int gridMarginY;
        int marginX;
        int marginY;
        int commentOffset;
        int titleOffset;
        Array<char> comment;
        Array<char> titleProp;
        COMMENT_POS commentPos;
        MultilineTextLayout commentAlign;
        MultilineTextLayout titleAlign;

        int gridColumnNumber;

    private:
        CanvasOptions(const CanvasOptions&);
    };

    class RenderOptions
    {
    public:
        RenderOptions();
        void clear();

        Vec3f backgroundColor;
        Vec3f baseColor;
        bool highlightThicknessEnable;
        float highlightThicknessFactor;
        bool highlightColorEnable;
        Vec3f highlightColor;
        Vec3f aamColor;
        float commentFontFactor;
        float commentSpacing;
        float titleFontFactor;
        float titleSpacing;
        Vec3f commentColor;
        Vec3f titleColor;
        Vec3f dataGroupColor;
        LABEL_MODE labelMode;
        bool highlightedLabelsVisible;
        bool boldBondDetection;
        bool implHVisible;
        DINGO_MODE mode;
        Output* output;
        PVOID hdc;
        bool showBondIds;
        bool showBondEndIds;
        bool atomBondIdsFromOne;
        bool showNeighborArcs;
        bool showAtomIds;
        bool showValences;
        bool atomColoring;
        STEREO_STYLE stereoMode;
        bool showReactingCenterUnchanged;
        bool centerDoubleBondWhenStereoAdjacent;
        bool showCycles; // for diagnostic purposes
        bool agentsBelowArrow;
        bool collapseSuperatoms;
        Array<char> atomColorProp;
        AutoPtr<RenderCdxmlContext> cdxml_context;

    private:
        RenderOptions(const RenderOptions&);
    };

} // namespace indigo

#define QUERY_MOL_BEGIN(mol)                                                                                                                                   \
    if (mol->isQueryMolecule())                                                                                                                                \
    {                                                                                                                                                          \
        QueryMolecule& qmol = mol->asQueryMolecule()
#define QUERY_MOL_END }

#define QUERY_RXN_BEGIN1(rxn)                                                                                                                                  \
    if (rxn->isQueryReaction())                                                                                                                                \
    {                                                                                                                                                          \
        QueryReaction& qr = rxn->asQueryReaction()

#define QUERY_RXN_BEGIN                                                                                                                                        \
    if (_r->isQueryReaction())                                                                                                                                 \
    {                                                                                                                                                          \
        QueryReaction& qr = _r->asQueryReaction()
#define QUERY_RXN_END }

#endif //__render_common_h__