summaryrefslogtreecommitdiff
path: root/modules/xcos/macros/xcosValidateCompareBlock.sci
blob: 74e928fa046744536b6bfedf8db3961952584374 (plain)
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
//
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
//
//

function [status, message] = xcosValidateCompareBlock(block1, block2)
    status = %t;
    message = "";

    if (typeof(block1) <> "Block")
        error(999, sprintf(_("%s: Wrong type for argument #%d: A Block expected."), "xcosValidateCompareBlock", 1))
    end
    if (typeof(block2) <> "Block")
        error(999, sprintf(_("%s: Wrong type for argument #%d: A Block expected."), "xcosValidateCompareBlock", 2))
    end

    unconsistantFields = [];

    if or(block1.gui <> block2.gui)
        status = %f;
        unconsistantFields = [ unconsistantFields ; "gui"]
    end

    if or(block1.doc <> block2.doc)
        status = %f;
        unconsistantFields = [ unconsistantFields ; "doc"]
    end

    //
    // Compare block.graphics
    //
    graphics1 = block1.graphics;
    graphics2 = block2.graphics;
    graphicFields = ["orig" ; "sz" ; "flip" ; "theta" ; "exprs" ;
    "pin" ; "pout" ; "pein" ; "peout" ; "gr_i" ;
    "id"; "in_implicit" ; "out_implicit"]

    for i=1:size(graphicFields, "*")
        if or(graphics1(graphicFields(i)) <> graphics2(graphicFields(i)))
            status = %f;
            unconsistantFields = [ unconsistantFields ; "graphics." + graphicFields(i)]
        end
    end

    //
    // Compare block.model
    //
    model1 = block1.model;
    model2 = block2.model;
    modelFields = [ "sim" ;
    "in" ; "in2" ; "intyp" ;
    "out" ; "out2" ; "outtyp" ;
    "evtin" ; "evtout" ;
    "state" ; "dstate" ; "odstate" ;
    "rpar" ; "ipar" ; "opar" ;
    "blocktype" ;
    "firing" ; "dep_ut" ;
    "label" ;
    "nzcross" ; "nmode" ;
    "equations"
    ]
    for i=1:size(modelFields, "*")
        if or(model1(modelFields(i)) <> model2(modelFields(i)))
            status = %f;
            unconsistantFields = [ unconsistantFields ; "model." + modelFields(i)]
        end
    end

    if ~isempty(unconsistantFields)
        message = [];
        for i=1:size(unconsistantFields, "*")
            msg = sprintf(_("Field %s has different values."), unconsistantFields(i));
            message = [message; msg];
        end
    end

endfunction