Skip to content

Commit

Permalink
v10.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeura committed Jan 20, 2025
1 parent 260c0b1 commit 98063ab
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 115 deletions.
7 changes: 6 additions & 1 deletion demo/test-svg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ RUN_TEST \\ --script "'--cReset --cSize 300 -Q DBZH -c --palette \"\" -o out-\$


WRITE_DOC 'In a grid of images, originating from several radars and times, the images can be labelled automatically with \c --gTitles command, with option \c IMAGE_TITLES . '
RUN_TEST \\ --script "'--cReset --cSize 300 -Q DBZH -c --palette \"\" -o out-\${what:date}T\${what:time}-\${NOD}.png'" \\ --gGroup "'Examples of \${PLC} (\${NOD}) on \${what:date|%Y/%m/%d}'" --gTitles IMAGE_TITLE \\ 'data-kiira/*.h5' -o series-labelled.svg
RUN_TEST \\ --script "'--cReset --cSize 300 -Q DBZH -c --palette \"\" -o out-\${what:date}T\${what:time}-\${NOD}.png'" \\ --gGroup "'Examples of \${PLC} (\${NOD}) on \${what:date|%Y/%m/%d}'" --gTitles IMAGE_TITLE \\ 'data-kiira/*.h5' -o series-labelled.svg


WRITE_DOC 'A further example, with three levels of titles.'
RUN_TEST \\ --script "'--cReset --cSize 300 -Q DBZH -c --palette \"\" -o out-\${what:date}T\${what:time}-\${NOD}.png'" --gGroup 'Examples of Kiira case' --gTitles GROUP_TITLE,IMAGE_TITLE,MAIN_TITLE \\ data-kiira/201708121530_radar.polar.fikor.h5 data-kiira/201708121600_radar.polar.fiika.h5 -o series-labelled2.svg


echo -e "Created: \ndisplay ${OUTFILES[*]}"
2 changes: 1 addition & 1 deletion src/drain/image/SuperProber.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class SuperProber : public SegmentProber<int,int,SuperProberConf> {
EdgeTracker<int,int> edgeTracker(src, control);
edgeTracker.track(pos, dir);
if (edgeTracker.contour.size() > 0){
TreeSVG & contour = tree[drain::StringBuilder<'-'>("cont", pos.i, pos.j)](svg::POLYGON);
TreeSVG & contour = tree[drain::StringBuilder<'-'>("cont", pos.i, pos.j).str()](svg::POLYGON);
FlexibleVariable & c = contour->get("points");
c.setType(typeid(std::string));
c.setSeparator(0);
Expand Down
26 changes: 26 additions & 0 deletions src/drain/image/TreeSVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,32 @@ void NodeSVG::updateAlign(){

} // image::


template <> // for T (Tree class)
template <> // for K (path elem arg)
bool image::TreeSVG::hasChild(const image::svg::tag_t & type) const {
return hasChild(EnumDict<image::svg::tag_t>::dict.getKey(type, true)); // no error on non-existent dict entry
}


/// Automatic conversion of elem classes to strings.
/**
*
*/
template <> // for T (Tree class)
template <> // for K (path elem arg)
const image::TreeSVG & image::TreeSVG::operator[](const image::svg::tag_t & type) const {
return (*this)[EnumDict<image::svg::tag_t>::dict.getKey(type, false)];
}


template <> // for T (Tree class)
template <> // for K (path elem arg)
image::TreeSVG & image::TreeSVG::operator[](const image::svg::tag_t & type){
return (*this)[EnumDict<image::svg::tag_t>::dict.getKey(type, false)];
}


} // drain::


37 changes: 37 additions & 0 deletions src/drain/image/TreeSVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const drain::EnumDict<image::svg::tag_t>::dict_t & getDict();
template <>
const EnumDict<image::svg::tag_t>::dict_t EnumDict<image::svg::tag_t>::dict;

DRAIN_ENUM_OSTREAM(image::svg::tag_t)

namespace image {

// Future option
Expand Down Expand Up @@ -401,7 +403,42 @@ image::TreeSVG & image::TreeSVG::addChild(const image::TreeSVG::key_t & key){
return XML::xmlAddChild(*this, key);
}

/*
template <>
template <class K>
const image::TreeSVG::key_t & image::TreeSVG::getKey(const K & key){
return EnumDict<K>::dict.getKey(key, false);
}
*/

/* tested 2025/01/20 but caused problems with Hi5Tree("dataset2") etc.
template <>
template <typename K> // for K (path elem arg)
const image::TreeSVG::key_t & image::TreeSVG::getKey(const K & key){
return EnumDict<K>::dict.getKey(key, false);
}
template <>
template <> // for K (path elem arg)
inline
const image::TreeSVG::key_t & image::TreeSVG::getKey(const drain::StyleSelectorXML<image::NodeSVG> & selector){
return selector;
}
*/

template <> // for T (Tree class)
template <> // for K (path elem arg)
bool image::TreeSVG::hasChild(const image::svg::tag_t & type) const;


template <> // for T (Tree class)
template <> // for K (path elem arg)
image::TreeSVG & image::TreeSVG::operator[](const image::svg::tag_t & type);

template <> // for T (Tree class)
template <> // for K (path elem arg)
const image::TreeSVG & image::TreeSVG::operator[](const image::svg::tag_t & type) const ;

} // drain::

Expand Down
10 changes: 5 additions & 5 deletions src/drain/image/TreeUtilsSVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ void TreeUtilsSVG::realignObjectHorz(TreeSVG & object, const Box<svg::coord_t> &
coord = anchorBoxHorz.x + anchorBoxHorz.width;
break;
case AlignBase::Pos::FILL:
mout.suspicious<LOG_WARNING>("Alignment:: ANCHOR has fill request: HORZ FILL");
// Maybe ok, since GROUP can be an anchor but also
// mout.suspicious<LOG_WARNING>("Alignment:: ANCHOR has fill request: HORZ FILL");
break;
case AlignBase::Pos::UNDEFINED_POS: // -> consider MID or some absolute value, or margin. Or error:
// mout.unimplemented<LOG_WARNING>("Alignment::Pos: ", AlignSVG::Owner::ANCHOR, '/', AlignBase::Axis::HORZ, '=', pos);
Expand Down Expand Up @@ -234,7 +235,7 @@ void TreeUtilsSVG::realignObjectHorz(TreeSVG & object, const Box<svg::coord_t> &
break;
case AlignBase::Pos::FILL:
//mout.experimental("STRETCHING..." );mout.experimental("STRETCHING..." );
mout.experimental("FILL:ing horz: ", obox, " width -> ", anchorBoxHorz.width);
mout.experimental<LOG_DEBUG>("FILL:ing horz: ", obox, " width -> ", anchorBoxHorz.width);
coord = anchorBoxHorz.x;
obox.setWidth(anchorBoxHorz.width);

Expand All @@ -257,7 +258,6 @@ void TreeUtilsSVG::realignObjectVert(TreeSVG & object, const Box<svg::coord_t> &
svg::coord_t coord;
realignObjectVert(object, anchorBoxVert, coord);

// Point2D<svg::coord_t> offset(0, coord - object->getBoundingBox().y);
TranslatorSVG translator(0, coord - object->getBoundingBox().y);
TreeUtils::traverse(translator, object);

Expand Down Expand Up @@ -334,7 +334,7 @@ void TreeUtilsSVG::realignObjectVert(TreeSVG & object, const Box<svg::coord_t> &
break;
case AlignBase::Pos::FILL:
//mout.experimental("STRETCHING..." );mout.experimental("STRETCHING..." );
mout.experimental("FILL:ing vert: ", obox, " height ");
mout.experimental<LOG_DEBUG>("FILL:ing vert: ", obox, " height ");
coord = anchorBoxVert.y;
obox.setHeight(anchorBoxVert.height);
break;
Expand Down Expand Up @@ -655,7 +655,7 @@ void TreeUtilsSVG::superAlign(TreeSVG & object, AlignBase::Axis orientation, Lay
bboxAnchorVert = & entry.second->getBoundingBox();
}

mout.accept<LOG_NOTICE>("Expanding ... ", objectBBox, " horz:", *bboxAnchorHorz, " vert:", *bboxAnchorVert);
mout.accept<LOG_DEBUG>("Expanding ... ", objectBBox, " horz:", *bboxAnchorHorz, " vert:", *bboxAnchorVert);
/// mout.accept<LOG_NOTICE>("Expanding ... ", bbox, " now, after: ", entry.second.data);

}
Expand Down
55 changes: 51 additions & 4 deletions src/drain/util/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,22 +478,24 @@ class DRAIN_TREE_NAME { // : public AmbiValue<T,typename P::elem_t> { //: public
return retrieveChild(key);
}

/// NEW 2025 Child addressing operator
/// NEW 2025 templated child addressing operator
/**
* Allows using EnumDict enums as keys, for example.
*
*/
template <class K>
inline
tree_t & operator[](const K & key){
return retrieveChild(static_cast<key_t>(key));
// return retrieveChild(getKey(key)); // 2025
return retrieveChild(static_cast<key_t>(key)); // OLD
}

/// NEW 2025 Child addressing operator
/// NEW 2025 templated child addressing operator
template <class K>
inline
const tree_t & operator[](const K & key) const {
return retrieveChild(static_cast<key_t>(key));
// return retrieveChild(getKey(key)); // 2025
return retrieveChild(static_cast<key_t>(key)); // OLD
}


Expand Down Expand Up @@ -745,6 +747,14 @@ x * \see clearData()
};


template <typename K>
inline
bool hasChild(const K &key) const {
//return hasChild(getKey(key)); 2025
return hasChild(static_cast<key_t>(key)); // OLDISH
}


inline
bool hasPath(const path_t & path) const {
return hasPath(path.begin(), path.end());
Expand Down Expand Up @@ -909,6 +919,36 @@ x * \see clearData()
static
const tree_t emptyNode;

/// "Default implementation" of key conversion – the identity mapping.
/*
* As an option, child nodes can be addressed using keys which are not of key_y type, but can be converted to such.
*/
/*
static inline
const key_t & getKey(const key_t & key){
return key;
}
*/

/// Conversion of char array to key type, which itself should never be a char array.
/*
static inline
key_t getKey(const char * key){
return key_t(key);
}
*/

/// Mapping of keys of external type - for example an enumerated type - to native \c key_t type.
/*
* As an option, child nodes can be addressed using keys which are not of key_y type, but can be converted to such.
* Not that this version returns a constant reference.
*/
/*
template <typename K>
static
const key_t & getKey(const K & key); // left undefined!
*/

/// Checks if there is a node with a given path name.
/** Could be called hasDescendant; hence is like hasChild() but calls children recursively.
*
Expand Down Expand Up @@ -1002,6 +1042,13 @@ x * \see clearData()
template <class T, bool EXCLUSIVE, class P>
const DRAIN_TREE_NAME<T,EXCLUSIVE, P> DRAIN_TREE_NAME<T,EXCLUSIVE,P>::emptyNode;

/*
template <class T, bool EXCLUSIVE, class P>
template <typename K>
typename DRAIN_TREE_NAME<T,EXCLUSIVE,P>::key_t DRAIN_TREE_NAME<T,EXCLUSIVE,P>::getKey(const K & key){
return typename DRAIN_TREE_NAME<T,EXCLUSIVE,P>::key_t(key); // for example, std::string("myKey")
}
*/


// Certified.
Expand Down
7 changes: 7 additions & 0 deletions src/drain/util/TreeXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ drain::UnorderedMultiTree<NodeXML<E>,EX,P> & drain::UnorderedMultiTree<NodeXML<E
}
*/

/*
template <class N, bool EX, class P>
template <typename K> // for K (path elem arg)
const typename drain::UnorderedMultiTree<N,EX,P>::key_t & drain::UnorderedMultiTree<N,EX,P>::getKey(const K & key){
return drain::EnumDict<K>::dict.getKey(key, false);
}
*/



Expand Down
9 changes: 4 additions & 5 deletions src/drain/util/XML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void XML::setText(const std::string & s) {

drain::Logger mout(__FILE__,__FUNCTION__);

mout.accept<LOG_WARNING>("setting text for elem type=", type, ", text: ", s); // *
// mout.accept<LOG_WARNING>("setting text for elem type=", type, ", text: ", s); // *
// TODO: warn if elem supports no ctext (like svg::CIRCLE or svg::RECT)

switch (type){
Expand All @@ -86,11 +86,10 @@ void XML::setText(const std::string & s) {
mout.special(s, " -> ", style);
*/
break;
case XML::STYLE_SELECT:
mout.info("parsing text to CSS definition");
//setValues(s, ':', ';');
case XML::STYLE_SELECT: // OK!
mout.debug("parsing text to CSS definition");
drain::SmartMapTools::setValues(getAttributes(), s, ';', ':', " \t\n");
mout.special(s, " -> ", getAttributes());
mout.special<LOG_DEBUG>(s, " -> ", getAttributes());
break;
case XML::UNDEFINED:
type = CTEXT;
Expand Down
34 changes: 20 additions & 14 deletions src/drain/util/XML.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ class XML : protected ReferenceMap2<FlexibleVariable> {
url = s;
}

template <class ...T>
inline
void setName(const T & ...args){
setAttribute("data-name", drain::StringBuilder<>(args...));
}


// ---------------- Attributes ---------------

Expand Down Expand Up @@ -443,9 +449,9 @@ class XML : protected ReferenceMap2<FlexibleVariable> {
/**
* \tparam XML - xml tree structure (TreeXML, TreeSVG, TreeHTML)
*/
template <typename XML>
template <typename TX>
static inline
XML & xmlAssign(XML & dst, const XML & src){
TX & xmlAssign(TX & dst, const TX & src){

if (&src != &dst){
dst.clear();
Expand All @@ -462,9 +468,9 @@ class XML : protected ReferenceMap2<FlexibleVariable> {
/**
* \tparam XML - xml tree structure (TreeXML, TreeSVG, TreeHTML)
*/
template <typename X>
template <typename TX>
static inline
X & xmlAssign(X & dst, const typename X::xml_node_t & src){
TX & xmlAssign(TX & dst, const typename TX::xml_node_t & src){

if (&src != &dst.data){
dst->clear();
Expand Down Expand Up @@ -502,26 +508,26 @@ class XML : protected ReferenceMap2<FlexibleVariable> {
/**
* \tparam T - XML tree
*/
template <typename XML, typename V>
template <typename TX, typename V>
static inline
XML & xmlAssign(XML & tree, const V & arg){
TX & xmlAssign(TX & tree, const V & arg){
tree->set(arg);
return tree;
}

/// Tree
/**
*
* \tparam TX - xml tree
*/
template <typename T>
template <typename TX>
static
//T & xmlAssign(T & tree, std::initializer_list<std::pair<const char *,const char *> > l){
T & xmlAssign(T & tree, std::initializer_list<std::pair<const char *,const Variable> > l){
TX & xmlAssign(TX & tree, std::initializer_list<std::pair<const char *,const Variable> > l){

switch (static_cast<intval_t>(tree->getType())){
case STYLE:
for (const auto & entry: l){
T & elem = tree[entry.first];
TX & elem = tree[entry.first];
elem->setType(STYLE_SELECT);
drain::SmartMapTools::setValues(elem->getAttributes(), entry.second, ';', ':', std::string(" \t\n"));
}
Expand All @@ -544,9 +550,9 @@ class XML : protected ReferenceMap2<FlexibleVariable> {
* Forward definition – type can be set only upon construction of a complete
*
*/
template <typename T>
template <typename TX>
static inline
T & xmlSetType(T & tree, const typename T::node_data_t::xml_tag_t & type){
TX & xmlSetType(TX & tree, const typename TX::node_data_t::xml_tag_t & type){
tree->setType(type);
return tree;
}
Expand All @@ -561,7 +567,7 @@ class XML : protected ReferenceMap2<FlexibleVariable> {
template <typename T>
static
T & xmlAddChild(T & tree, const std::string & key){
typename T::node_data_t::xml_tag_t type = xmlGuessType(tree.data);
typename T::node_data_t::xml_tag_t type = xmlRetrieveDefaultType(tree.data);

if (!key.empty()){
return tree[key](type);
Expand Down Expand Up @@ -589,7 +595,7 @@ class XML : protected ReferenceMap2<FlexibleVariable> {

template <typename N>
static
typename N::xml_tag_t xmlGuessType(const N & parentNode){
typename N::xml_tag_t xmlRetrieveDefaultType(const N & parentNode){
typedef typename N::xml_default_elem_map_t map_t;
const typename map_t::const_iterator it = N::xml_default_elems.find(parentNode.getNativeType());
if (it != N::xml_default_elems.end()){
Expand Down
Loading

0 comments on commit 98063ab

Please sign in to comment.