Python fixup after code review

This commit is contained in:
Gaute Lindkvist 2020-03-05 08:48:13 +01:00
parent c23e27eef0
commit b77c057e7d
6 changed files with 87 additions and 39 deletions

View File

@ -206,20 +206,31 @@ QString PdmPythonGenerator::generate(PdmObjectFactory* factory) const
QString commentDataType = field->xmlCapability()->isVectorField() ?
QString("List of %1").arg(scriptDataType) : scriptDataType;
QString firstItemTag = pdmChildField ? QString("[0]") : QString("");
QString fullComment =
QString(" \"\"\"%1\n Returns:\n %2\n \"\"\"")
.arg(comment)
.arg(commentDataType);
QString fieldCode = QString(" def %1(self):\n%2\n return "
"self.children(\"%3\", %4)%5\n")
.arg(snake_field_name)
.arg(fullComment)
.arg(scriptability->scriptFieldName())
.arg(scriptDataType)
.arg(firstItemTag);
classMethodsGenerated[field->ownerClass()][snake_field_name] = fieldCode;
if (pdmChildField)
{
QString fieldCode = QString(" def %1(self):\n%2\n return "
"self.children(\"%3\", %4)[0] if len(self.children) > 0 else None\n")
.arg(snake_field_name)
.arg(fullComment)
.arg(scriptability->scriptFieldName())
.arg(scriptDataType);
classMethodsGenerated[field->ownerClass()][snake_field_name] = fieldCode;
}
else
{
QString fieldCode = QString(" def %1(self):\n%2\n return "
"self.children(\"%3\", %4)\n")
.arg(snake_field_name)
.arg(fullComment)
.arg(scriptability->scriptFieldName())
.arg(scriptDataType);
classMethodsGenerated[field->ownerClass()][snake_field_name] = fieldCode;
}
}
}
}

View File

@ -1,20 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//##################################################################################################
//
// Copyright (C) 2017 Statoil ASA
// Custom Visualization Core library
// Copyright (C) Ceetron Solutions AS
//
// ResInsight 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, either version 3 of the License, or
// (at your option) any later version.
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
/////////////////////////////////////////////////////////////////////////////////
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#include "cafPdmScriptIOMessages.h"
#include <QTextStream>

View File

@ -1,20 +1,38 @@
/////////////////////////////////////////////////////////////////////////////////
//##################################################################################################
//
// Copyright (C) 2017 Statoil ASA
// Custom Visualization Core library
// Copyright (C) Ceetron Solutions AS
//
// ResInsight 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, either version 3 of the License, or
// (at your option) any later version.
// This library may be used under the terms of either the GNU General Public License or
// the GNU Lesser General Public License as follows:
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
// GNU General Public License Usage
// This library 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, either version 3 of the License, or
// (at your option) any later version.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
/////////////////////////////////////////////////////////////////////////////////
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
// for more details.
//
// GNU Lesser General Public License Usage
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
// for more details.
//
//##################################################################################################
#pragma once
#include <QString>

View File

@ -12,6 +12,10 @@ template < typename FieldType>
class PdmFieldXmlCap : public PdmXmlFieldHandle
{
public:
// Type traits magic to check if a template argument is a vector
template<typename T> struct is_vector : public std::false_type {};
template<typename T, typename A> struct is_vector<std::vector<T, A>> : public std::true_type {};
PdmFieldXmlCap(FieldType* field, bool giveOwnership) : PdmXmlFieldHandle(field, giveOwnership)
{
m_field = field;

View File

@ -54,7 +54,9 @@ void PdmXmlFieldHandle::disableIO()
//--------------------------------------------------------------------------------------------------
/// Returns the classKeyword of the child class type, if this field is supposed to contain pointers
/// to PdmObjectHandle derived objects.
/// Returns typeid(DataType).name() if the field is not containing some PdmObjectHandle type
/// Returns typeid(DataType).name() if the field is not containing some PdmObjectHandle type.
/// Warning: typeid(DataType).name() is compiler implementation specific and thus you should not
/// Compare this with a predefined literal, like "double" or "float". Instead compare with typeid(double).name().
//--------------------------------------------------------------------------------------------------
QString PdmXmlFieldHandle::dataTypeName() const
{

View File

@ -22,11 +22,6 @@ class PdmReferenceHelper;
//==================================================================================================
class PdmXmlFieldHandle : public PdmFieldCapability
{
public:
// Type traits magic to check if a template argument is a vector
template<typename T> struct is_vector : public std::false_type {};
template<typename T, typename A> struct is_vector<std::vector<T, A>> : public std::true_type {};
public:
PdmXmlFieldHandle(PdmFieldHandle* owner , bool giveOwnership);
~PdmXmlFieldHandle() override { }