Handle DrawLinesMatchesFlags correctly
MODIFY
binding-generator/src/class.rs
binding-generator/src/class.rs
@@ -2,12 +2,12 @@ use std::borrow::Cow;
use std::collections::HashSet;
use std::{fmt, hash, iter};
-use clang::Entity;
+use clang::{Entity, EntityKind};
use crate::entity::{WalkAction, WalkResult};
use crate::type_ref::{Constness, CppNameStyle};
use crate::{
- settings, Const, DefaultElement, Element, EntityElement, EntityExt, Field, Func, FunctionTypeHint, GeneratedType,
+ settings, Const, DefaultElement, Element, EntityElement, EntityExt, Enum, Field, Func, FunctionTypeHint, GeneratedType,
GeneratorEnv, StrExt, TypeRef,
};
@@ -130,6 +130,24 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
// self.is_abstract() || self.has_descendants() || settings::FORCE_CLASS_TRAIT.contains(self.cpp_name(CppNameStyle::Reference).as_ref())
}
+ /// Special case of an empty class with only an anonymous enum inside (e.g. DrawLinesMatchesFlags)
+ pub fn as_enum(&self) -> Option<Enum<'tu>> {
+ if !self.has_methods() && !self.has_fields() && !self.has_descendants() && !self.has_bases() {
+ let children = self.entity.get_children();
+ if let [single] = children.as_slice() {
+ if matches!(single.get_kind(), EntityKind::EnumDecl) {
+ Some(Enum::new_ext(*single, self.cpp_name(CppNameStyle::Declaration).into_owned()))
+ } else {
+ None
+ }
+ } else {
+ None
+ }
+ } else {
+ None
+ }
+ }
+
pub fn has_clone(&self) -> bool {
self
.for_each_method(|m| WalkAction::continue_until(m.is_clone()))

MODIFY
binding-generator/src/lib.rs
binding-generator/src/lib.rs
// copy-pasted form python generator (may be obsolete):
// fixme returning MatAllocator (trait) by reference is bad, check knearestneighbour
-// fixme: https://docs.opencv.org/4.x/d8/d6f/structcv_1_1line__descriptor_1_1DrawLinesMatchesFlags.html is an empty class with an anonymous enum, generate that enum
#![allow(clippy::nonminimal_bool)] // pattern `!type_ref.as_vector().is_some()` used for more clarity

MODIFY
binding-generator/src/writer/rust_native/element.rs
binding-generator/src/writer/rust_native/element.rs
@@ -46,7 +46,10 @@ impl DefaultRustNativeElement {
while let Some(parent) = e.get_semantic_parent() {
match parent.get_kind() {
EntityKind::ClassDecl | EntityKind::StructDecl => {
- parts.push(parent.get_name().expect("Can't get parent name"));
+ let parent_name = parent.get_name().expect("Can't get parent name");
+ if parts.last().map_or(true, |last| last != &parent_name) {
+ parts.push(parent_name);
+ }
}
EntityKind::EnumDecl => {
if parent.is_scoped() {

MODIFY
binding-generator/src/writer/rust_native/mod.rs
binding-generator/src/writer/rust_native/mod.rs
@@ -158,6 +158,12 @@ impl GeneratorVisitor for RustNativeBindingWriter<'_> {
fn visit_class(&mut self, class: Class) {
self.emit_debug_log(&class);
+ if let Some(enm) = class.as_enum() {
+ self.enums.push((
+ enm.rust_name(NameStyle::decl()).into_owned(),
+ enm.gen_rust(self.opencv_version),
+ ));
+ } else {
if class.is_trait() {
self.prelude_traits.push(format!(
"super::{}",
@@ -173,6 +179,7 @@ impl GeneratorVisitor for RustNativeBindingWriter<'_> {
self.export_classes.push((name.clone(), class.gen_rust_exports()));
self.cpp_classes.push((name, class.gen_cpp()));
}
+ }
fn visit_generated_type(&mut self, typ: GeneratedType) {
let typ = typ.as_ref();

MODIFY
docs/line_descriptor.rs
docs/line_descriptor.rs
@@ -71,7 +71,7 @@ pub mod line_descriptor {
//! representation of a single LBD.
use crate::{mod_prelude::*, core, sys, types};
pub mod prelude {
- pub use { super::BinaryDescriptor_ParamsTraitConst, super::BinaryDescriptor_ParamsTrait, super::BinaryDescriptorTraitConst, super::BinaryDescriptorTrait, super::LSDDetectorTraitConst, super::LSDDetectorTrait, super::BinaryDescriptorMatcherTraitConst, super::BinaryDescriptorMatcherTrait, super::DrawLinesMatchesFlagsTraitConst, super::DrawLinesMatchesFlagsTrait };
+ pub use { super::BinaryDescriptor_ParamsTraitConst, super::BinaryDescriptor_ParamsTrait, super::BinaryDescriptorTraitConst, super::BinaryDescriptorTrait, super::LSDDetectorTraitConst, super::LSDDetectorTrait, super::BinaryDescriptorMatcherTraitConst, super::BinaryDescriptorMatcherTrait };
}
/// Output image matrix will be created (Mat::create),
@@ -87,6 +87,24 @@ pub mod line_descriptor {
pub const DrawLinesMatchesFlags_NOT_DRAW_SINGLE_LINES: i32 = 2;
pub const MLN10: f64 = 2.30258509299404568402;
pub const RELATIVE_ERROR_FACTOR: f64 = 100.0;
+ #[repr(C)]
+ #[derive(Copy, Clone, Debug, PartialEq, Eq)]
+ pub enum DrawLinesMatchesFlags {
+ /// Output image matrix will be created (Mat::create),
+ /// i.e. existing memory of output image may be reused.
+ /// Two source images, matches, and single keylines
+ /// will be drawn.
+ DEFAULT = 0,
+ /// Output image matrix will not be
+ /// created (using Mat::create). Matches will be drawn
+ /// on existing content of output image.
+ DRAW_OVER_OUTIMG = 1,
+ /// Single keylines will not be drawn.
+ NOT_DRAW_SINGLE_LINES = 2,
+ }
+
+ opencv_type_enum! { crate::line_descriptor::DrawLinesMatchesFlags }
+
pub type uint16 = u16;
pub type uint32 = u32;
pub type uint64 = u64;
@@ -918,45 +936,6 @@ pub mod line_descriptor {
boxed_cast_base! { BinaryDescriptorMatcher, core::Algorithm, cv_BinaryDescriptorMatcher_to_Algorithm }
- /// Constant methods for [crate::line_descriptor::DrawLinesMatchesFlags]
- pub trait DrawLinesMatchesFlagsTraitConst {
- fn as_raw_DrawLinesMatchesFlags(&self) -> *const c_void;
-
- }
-
- /// Mutable methods for [crate::line_descriptor::DrawLinesMatchesFlags]
- pub trait DrawLinesMatchesFlagsTrait: crate::line_descriptor::DrawLinesMatchesFlagsTraitConst {
- fn as_raw_mut_DrawLinesMatchesFlags(&mut self) -> *mut c_void;
-
- }
-
- /// struct for drawing options
- pub struct DrawLinesMatchesFlags {
- ptr: *mut c_void
- }
-
- opencv_type_boxed! { DrawLinesMatchesFlags }
-
- impl Drop for DrawLinesMatchesFlags {
- fn drop(&mut self) {
- extern "C" { fn cv_DrawLinesMatchesFlags_delete(instance: *mut c_void); }
- unsafe { cv_DrawLinesMatchesFlags_delete(self.as_raw_mut_DrawLinesMatchesFlags()) };
- }
- }
-
- unsafe impl Send for DrawLinesMatchesFlags {}
-
- impl crate::line_descriptor::DrawLinesMatchesFlagsTraitConst for DrawLinesMatchesFlags {
- #[inline] fn as_raw_DrawLinesMatchesFlags(&self) -> *const c_void { self.as_raw() }
- }
-
- impl crate::line_descriptor::DrawLinesMatchesFlagsTrait for DrawLinesMatchesFlags {
- #[inline] fn as_raw_mut_DrawLinesMatchesFlags(&mut self) -> *mut c_void { self.as_raw_mut() }
- }
-
- impl DrawLinesMatchesFlags {
- }
-
/// A class to represent a line
///
/// As aformentioned, it is been necessary to design a class that fully stores the information needed to

Handle DrawLinesMatchesFlags correctly